Correctly set up file ids from list_files

This commit is contained in:
Savanni D'Gerinel 2023-09-25 00:17:34 -04:00
parent ee5f4646df
commit 94aa67a156
1 changed files with 12 additions and 10 deletions

View File

@ -116,18 +116,19 @@ impl Store {
pub fn list_files(&self) -> Result<HashSet<FileId>, ReadFileError> { pub fn list_files(&self) -> Result<HashSet<FileId>, ReadFileError> {
let paths = std::fs::read_dir(&self.files_root)?; let paths = std::fs::read_dir(&self.files_root)?;
Ok(paths let info_files = paths
.into_iter() .into_iter()
.map(|path| { .filter_map(|path| {
FileId::from( let path_ = path.unwrap().path();
path.unwrap() if path_.extension().and_then(|s| s.to_str()) == Some("json") {
.path() let stem = path_.file_stem().and_then(|s| s.to_str()).unwrap();
.file_stem() Some(FileId::from(FileId::from(stem)))
.and_then(|s| s.to_str()) } else {
.unwrap(), None
) }
}) })
.collect::<HashSet<FileId>>()) .collect::<HashSet<FileId>>();
Ok(info_files)
} }
pub fn add_file( pub fn add_file(
@ -237,6 +238,7 @@ mod test {
println!("ids: {:?}", ids); println!("ids: {:?}", ids);
assert_eq!(ids.len(), 1); assert_eq!(ids.len(), 1);
assert!(ids.contains(&id));
}); });
} }
} }