~sjm/sri

231860063bf094b9d031703e8f20cad30a10e924 — Sam Marshall 7 months ago eb4edda master
check for new files in folder when running sri
3 files changed, 23 insertions(+), 1 deletions(-)

M src/main.rs
M src/sri_file.rs
M src/sri_file/sri_files.rs
M src/main.rs => src/main.rs +8 -1
@@ 18,7 18,14 @@ fn main() -> io::Result<()> {
    let current_dir = env::current_dir()?;

    let files: SriFiles = match SriFiles::fetch_from_dotfile(&current_dir) {
        Ok(f) => Ok(SriFiles::new(f)),
        Ok(f) => {
            let mut files = SriFiles::new(f);
            let new_files = SriFiles::fetch_from_dir(&current_dir)?;

            files.ingest(new_files);

            Ok(files)
        },
        Err(FilesystemError::NoFile) => SriFiles::fetch_from_dir(&current_dir).map(|f| SriFiles::new(f)),
        Err(FilesystemError::NoFolder) => {
            fs::create_dir(sri_dir(&current_dir).unwrap())?;

M src/sri_file.rs => src/sri_file.rs +6 -0
@@ 49,6 49,12 @@ impl Scheduled<SriFile> for SriFile {
    }
}

impl PartialEq for SriFile {
    fn eq(&self, other: &Self) -> bool {
        self.path.eq(&other.path)
    }
}

#[cfg(test)]
mod tests {


M src/sri_file/sri_files.rs => src/sri_file/sri_files.rs +9 -0
@@ 66,6 66,15 @@ impl SriFiles {

        (already, not_ready_to_schedule)
    }

    /// add new files, ignore existing ones
    pub fn ingest(&mut self, files: Vec<SriFile>) {
        for file in files {
            if !self.files.contains(&file) {
                self.files.push(file)
            }
        }
    }
}

impl Filesystem for SriFiles {