Fix bugs in syncback process and enhance error handling

- Resolved issues with nested orphan file removal, ensuring that both top-level and nested orphan files are correctly handled.
- Improved directory removal logic to gracefully handle cases where directories may have already been removed, preventing crashes.
- Enhanced the path scanning algorithm to accurately collect all source directories defined in the project, addressing missing paths in the syncback process.
- Updated logging to provide clearer debug information during directory scanning and error handling in the syncback operations.
This commit is contained in:
Joe 2026-02-01 19:14:12 -06:00
parent 4a66eff938
commit fe1ac1dd95
5 changed files with 145 additions and 54 deletions

View file

@ -108,7 +108,18 @@ impl FsSnapshot {
lock.write(base_path.join(path), contents)?;
}
for dir_path in &self.removed_dirs {
lock.remove_dir_all(base_path.join(dir_path))?;
let full_path = base_path.join(dir_path);
match lock.remove_dir_all(&full_path) {
Ok(()) => (),
// Directory might have already been removed (e.g., added twice via different code paths)
Err(err) if err.kind() == io::ErrorKind::NotFound => {
log::debug!(
"Directory already removed or doesn't exist: {}",
full_path.display()
);
}
Err(err) => return Err(err),
}
}
// Only remove files that aren't already inside a directory we're removing.
// remove_dir_all already deleted those files recursively.