<commit_before>use fuse::{Request, ReplyData};
use libc::ENOENT;
use rustc_serialize::json;

use fs::constants;
use fs::flags;
use fs::GoodDataFS;
use fs::inode;
use gd;
use object;

pub fn read(fs: &mut GoodDataFS,
            _req: &Request,
            ino: u64,
            fh: u64,
            offset: u64,
            size: u32,
            reply: ReplyData) {
    println!("GoodDataFS::read() - Reading inode {}, fh {}, offset {}, size {}",
             ino,
             fh,
             offset,
             size);
    let inode = inode::Inode::deserialize(ino);
    if ino == constants::INODE_USER {
        user_json(fs, reply, offset as usize)
    } else if ino == constants::INODE_PROJECTS_JSON {
        projects_json(fs, reply, offset as usize)
    } else {
        if inode.project > 0 && (inode.reserved == flags::ReservedFile::FeatureFlagsJson as u8) {
            feature_flags_json(fs, inode, reply, offset as usize)
        } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::ProjectJson as u8) {
            project_json(fs, inode, reply, offset as usize)
        } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::PermissionsJson as u8) {
            permissions_json(fs, inode, reply, offset as usize)
        } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::RolesJson as u8) {
            roles_json(fs, inode, reply, offset as usize);
        } else {
            reply.error(ENOENT);
        }
    }
}

fn projects_json(fs: &mut GoodDataFS, reply: ReplyData, offset: usize) {
    println!("GoodDataFS::read() - Reading {}",
             constants::PROJECTS_JSON_FILENAME);
    let json = format!("{}\n",
                       json::as_pretty_json(&fs.client.projects()).to_string());
    // let json: String = fs.client.projects().clone().unwrap().into();
    reply.data(&json.as_bytes()[offset as usize..]);
}

fn feature_flags_json(fs: &mut GoodDataFS, inode: inode::Inode, reply: ReplyData, offset: usize) {
    println!("GoodDataFS::read() - Reading {}",
             constants::FEATURE_FLAGS_JSON_FILENAME);

    let pid = (inode.project - 1) as usize;
    let project: &object::Project = &fs.client().projects().as_ref().unwrap()[pid].clone();
    let feature_flags = project.feature_flags(&mut fs.client);
    if feature_flags.is_some() {
        let json: String = feature_flags.unwrap().into();
        reply.data(&json.as_bytes()[offset as usize..]);
    }
}
<commit_msg>Matching pattern<commit_after>use fuse::{Request, ReplyData};
use libc::ENOENT;
use rustc_serialize::json;

use fs::constants;
use fs::flags;
use fs::GoodDataFS;
use fs::inode;
use gd;
use object;

pub fn read(fs: &mut GoodDataFS,
            _req: &Request,
            ino: u64,
            fh: u64,
            offset: u64,
            size: u32,
            reply: ReplyData) {
    let inode = inode::Inode::deserialize(ino);
    println!("GoodDataFS::read() - Reading inode {:?}, fh {}, offset {}, size {}",
             inode,
             fh,
             offset,
             size);

    match ino {
        constants::INODE_USER => user_json(fs, reply, offset as usize),
        constants::INODE_PROJECTS_JSON => projects_json(fs, reply, offset as usize),
        _ => {
            if inode.project > 0 &&
               (inode.reserved == flags::ReservedFile::FeatureFlagsJson as u8) {
                feature_flags_json(fs, inode, reply, offset as usize)
            } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::ProjectJson as u8) {
                project_json(fs, inode, reply, offset as usize)
            } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::PermissionsJson as u8) {
                permissions_json(fs, inode, reply, offset as usize)
            } else if inode.project > 0 && (inode.reserved == flags::ReservedFile::RolesJson as u8) {
                roles_json(fs, inode, reply, offset as usize);
            } else {
                reply.error(ENOENT);
            }
        }
    }
}

fn projects_json(fs: &mut GoodDataFS, reply: ReplyData, offset: usize) {
    println!("GoodDataFS::read() - Reading {}",
             constants::PROJECTS_JSON_FILENAME);
    let json = format!("{}\n",
                       json::as_pretty_json(&fs.client.projects()).to_string());
    // let json: String = fs.client.projects().clone().unwrap().into();
    reply.data(&json.as_bytes()[offset as usize..]);
}

fn feature_flags_json(fs: &mut GoodDataFS, inode: inode::Inode, reply: ReplyData, offset: usize) {
    println!("GoodDataFS::read() - Reading {}",
             constants::FEATURE_FLAGS_JSON_FILENAME);

    let pid = (inode.project - 1) as usize;
    let project: &object::Project = &fs.client().projects().as_ref().unwrap()[pid].clone();
    let feature_flags = project.feature_flags(&mut fs.client);
    if feature_flags.is_some() {
        let json: String = feature_flags.unwrap().into();
        reply.data(&json.as_bytes()[offset as usize..]);
    }
}

{'fraction_non_alphanumeric': 0.14588329336530775, 'fraction_numerical': 0.006794564348521183, 'mean_word_length': 2.5955459770114944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6674609', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1535, 'n_words': 361}