<commit_before>use std::fs::File;
use std::io::prelude::*;

use backend::Backend;
use platform::platform::Platform;
use provider::Provider;
use provider::file::FileProvider;
use provider::file::inline::posix::Posix;
use provider::file::shell::linux::Linux;

#[derive(Clone)]
pub struct Ubuntu {
    name: String,
    release: String,
}

fn detect_by_lsb_releae(content: &str) -> Option<Box<Platform>> {
    let mut lines = content.lines();
    let line = lines.next().unwrap();
    if line.starts_with("DISTRIB_ID") {
        let id = line.split("=").nth(1).unwrap().trim();
        if id == "Ubuntu" {
            let line = lines.next().unwrap();
            let release = line.split("=").nth(1).unwrap();
            let u = Ubuntu {
                name: id.to_string(),
                release: release.to_string(),
            };

            return Some(Box::new(u));
        }
    }
    None
}

impl Platform for Ubuntu {
    fn new() -> Ubuntu {
        Ubuntu {
            name: "".to_string(),
            release: "".to_string(),
        }
    }

    fn inline_detector(&self) -> Option<Box<Platform>> {
        let mut file = File::open("/etc/lsb-release").unwrap();
        let mut content = String::new();
        let _ = file.read_to_string(&mut content);
        detect_by_lsb_releae(&content)
    }

    fn shell_detector(&self, b: &Backend) -> Option<Box<Platform>> {
        let content = b.run_command("cat /etc/lsb-release").unwrap();
        detect_by_lsb_releae(&content)
    }

    fn get_provider(&self) -> Box<Provider> {
        let fp = FileProvider {
            inline: Box::new(Posix),
            shell: Box::new(Linux),
        };

        let p = Provider { file: Box::new(fp) };

        Box::new(p)
    }
}<commit_msg>Return none when fail to open /etc/lsdb-release<commit_after>use std::fs::File;
use std::io::prelude::*;

use backend::Backend;
use platform::platform::Platform;
use provider::Provider;
use provider::file::FileProvider;
use provider::file::inline::posix::Posix;
use provider::file::shell::linux::Linux;

#[derive(Clone, Debug)]
pub struct Ubuntu {
    name: String,
    release: String,
}

fn detect_by_lsb_releae(content: &str) -> Option<Box<Platform>> {
    let mut lines = content.lines();
    let line = lines.next().unwrap();
    if line.starts_with("DISTRIB_ID") {
        let id = line.split("=").nth(1).unwrap().trim();
        if id == "Ubuntu" {
            let line = lines.next().unwrap();
            let release = line.split("=").nth(1).unwrap();
            let u = Ubuntu {
                name: id.to_string(),
                release: release.to_string(),
            };

            return Some(Box::new(u));
        }
    }
    None
}

impl Platform for Ubuntu {
    fn new() -> Ubuntu {
        Ubuntu {
            name: "".to_string(),
            release: "".to_string(),
        }
    }

    fn inline_detector(&self) -> Option<Box<Platform>> {
        let mut file = match File::open("/etc/lsb-release") {
            Err(_) => return None,
            Ok(f) => f,
        };


        let mut content = String::new();
        let _ = file.read_to_string(&mut content);
        detect_by_lsb_releae(&content)
    }

    fn shell_detector(&self, b: &Backend) -> Option<Box<Platform>> {
        let content = match b.run_command("cat /etc/lsb-release") {
            Err(_) => return None,
            Ok(f) => f,
        };

        detect_by_lsb_releae(&content)
    }

    fn get_provider(&self) -> Box<Provider> {
        let fp = FileProvider {
            inline: Box::new(Posix),
            shell: Box::new(Linux),
        };

        let p = Provider { file: Box::new(fp) };

        Box::new(p)
    }
}
{'fraction_non_alphanumeric': 0.1635969664138678, 'fraction_numerical': 0.0010834236186348862, 'mean_word_length': 2.262367491166078, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '789521', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1165, 'n_words': 243}