fix(db): handling (again) existing files + tests
ci/woodpecker/push/woodpecker Pipeline failed Details

refactor/sveltekit
Tomáš Mládek 2023-12-11 21:35:41 +01:00
parent 3c4276e22d
commit f90f3fa189
1 changed files with 49 additions and 2 deletions

View File

@ -317,8 +317,13 @@ impl FsStore {
if let Some(idx) = maybe_existing_file {
existing_files_write.swap_remove(idx);
trace!("Unchanged: {:?}", path);
return Ok(UpdatePathOutcome::Unchanged(path));
return if existing_file.valid {
info!("Unchanged: {:?}", path);
Ok(UpdatePathOutcome::Unchanged(path))
} else {
info!("Re-added: {:?}", path);
Ok(UpdatePathOutcome::Added(path.clone()))
}
}
}
}
@ -936,6 +941,48 @@ mod test {
.filter(|upo| matches!(upo, UpdatePathOutcome::Removed(_)))
.count()
);
assert!(store.retrieve_all_files().unwrap().iter().filter(|f| f.path == "hello-world.txt").all(|f| !f.valid));
// Re-add the file
let file_path = temp_dir_path.join("hello-world.txt");
let mut tmp_file = File::create(file_path).unwrap();
writeln!(tmp_file, "Hello, World!").unwrap();
let job = job_container.add_job("RESCAN", "TEST JOB").unwrap();
let rescan_result = store.rescan_vault(
&open_result.db,
job,
UpdateOptions {
initial: quick,
tree_mode: BlobMode::default(),
},
);
assert!(rescan_result.is_ok());
let rescan_result = rescan_result.unwrap();
assert_eq!(rescan_result.len(), 3);
assert_eq!(
1,
rescan_result
.iter()
.filter(|upo| matches!(upo, UpdatePathOutcome::Unchanged(_)))
.count()
);
assert_eq!(
1,
rescan_result
.iter()
.filter(|upo| matches!(upo, UpdatePathOutcome::Skipped(_)))
.count()
);
assert_eq!(
1,
rescan_result
.iter()
.filter(|upo| matches!(upo, UpdatePathOutcome::Added(_)))
.count()
);
assert!(store.retrieve_all_files().unwrap().iter().filter(|f| f.path == "hello-world.txt").all(|f| f.valid));
}
/// Prepare a temporary filesystem structure for testing