From afa8134644cf238718c5adccdaa1f40178efa2bc Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 25 Sep 2023 00:17:34 -0400 Subject: [PATCH] Correctly set up file ids from list_files --- file-service/src/store/mod.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/file-service/src/store/mod.rs b/file-service/src/store/mod.rs index 227d8bb..9975788 100644 --- a/file-service/src/store/mod.rs +++ b/file-service/src/store/mod.rs @@ -116,18 +116,19 @@ impl Store { pub fn list_files(&self) -> Result, ReadFileError> { let paths = std::fs::read_dir(&self.files_root)?; - Ok(paths + let info_files = paths .into_iter() - .map(|path| { - FileId::from( - path.unwrap() - .path() - .file_stem() - .and_then(|s| s.to_str()) - .unwrap(), - ) + .filter_map(|path| { + let path_ = path.unwrap().path(); + if path_.extension().and_then(|s| s.to_str()) == Some("json") { + let stem = path_.file_stem().and_then(|s| s.to_str()).unwrap(); + Some(FileId::from(FileId::from(stem))) + } else { + None + } }) - .collect::>()) + .collect::>(); + Ok(info_files) } pub fn add_file( @@ -237,6 +238,7 @@ mod test { println!("ids: {:?}", ids); assert_eq!(ids.len(), 1); + assert!(ids.contains(&id)); }); } }