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 5c23427fdb
commit f204920216
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> {
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::<HashSet<FileId>>())
.collect::<HashSet<FileId>>();
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));
});
}
}