diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index 2925869..ec8d3c9 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -153,9 +153,15 @@ impl DB { let mut result = vec![]; for f in std::fs::read_dir(d.path()).expect("failed to list edited files") { - let f = f.expect("failed to list edited file"); - let base = f.path().display().to_string().split("/").last().unwrap().to_string(); - let set = match{ TODO find self.0.find(path.base(f)) OR init TasksAndMetadata{} } + let f = f.expect("failed to list edited file").path(); + let base = f.display().to_string().split("/").last().unwrap().to_string(); + let set = match self.0 + .iter() + .filter(|tasks_and_metadata| tasks_and_metadata.file.ends_with(format!("/{}", base))) + .nth(0) { + Some(set) => set.clone(), + None => TasksAndMetadata::new_with(base, TS::now(), Tasks::new()), + }; let edited = TasksAndMetadata::new(f.display().to_string()).expect("failed to read edited tasks");