diff --git a/src/main.rs b/src/main.rs index f4397f9..08e7025 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,9 +157,16 @@ async fn main() -> std::io::Result<()> { .watch("./projects/", RecursiveMode::Recursive) .unwrap(); - let paths = fs::read_dir(format!("{}/projects/", CONFIG.path_root)).unwrap(); + let mut paths: Vec = fs::read_dir(format!("{}/projects/", CONFIG.path_root)).unwrap().filter_map(|p| p.ok()).map(|p| p.path()).collect(); + paths.sort_by_cached_key(|path| path.file_name() + .and_then(|s| s.to_str()) + .and_then(|s| s.split('_').next()) + .and_then(|s| s.parse::().ok()) + .unwrap_or(50) + ); for path in paths { - projects.process(path.unwrap().path()); + debug!("found project {}", &path.display()); + projects.process(path); } let projects_ref = Arc::new(Mutex::new(projects)); diff --git a/src/models/projects.rs b/src/models/projects.rs index 3b50f34..044af1b 100644 --- a/src/models/projects.rs +++ b/src/models/projects.rs @@ -1,4 +1,4 @@ -use log::error; +use log::{error, debug}; use notify::{watcher, DebouncedEvent, RecommendedWatcher}; use yaml_rust::YamlLoader; use std::sync::mpsc::{channel, Receiver}; @@ -103,18 +103,21 @@ impl Projects { } pub fn value(&self) -> Arc>> { - self.rx.try_iter().for_each(|e: DebouncedEvent| match e { - DebouncedEvent::NoticeWrite(p) => self.process(p), - DebouncedEvent::NoticeRemove(p) => self.process(p), - DebouncedEvent::Create(p) => self.process(p), - DebouncedEvent::Write(p) => self.process(p), - DebouncedEvent::Chmod(p) => self.process(p), - DebouncedEvent::Remove(p) => { - self.value.lock().unwrap().remove(&String::from(p.file_name().unwrap().to_str().unwrap())); - }, - DebouncedEvent::Rename(_, p) => self.process(p), - _ => {} - }); + self.rx.try_iter().for_each(|e: DebouncedEvent| { + debug!("fs watch triggered!"); + match e { + DebouncedEvent::NoticeWrite(p) => self.process(p), + DebouncedEvent::NoticeRemove(p) => self.process(p), + DebouncedEvent::Create(p) => self.process(p), + DebouncedEvent::Write(p) => self.process(p), + DebouncedEvent::Chmod(p) => self.process(p), + DebouncedEvent::Remove(p) => { + self.value.lock().unwrap().remove(&String::from(p.file_name().unwrap().to_str().unwrap())); + }, + DebouncedEvent::Rename(_, p) => self.process(p), + _ => {} + } + }); self.value.clone() }