Enhance syncback logic for removed instances in ApiService

- Implemented functionality to delete files from the filesystem when instances are removed in Studio but exist in Rojo, ensuring proper synchronization.
- Added error handling for cases where the instance's filesystem path may not exist due to parent directory deletions.
- Introduced a new method, `syncback_removed_instance`, to encapsulate the logic for handling the removal of instances and their associated metadata files.
- Updated tests to verify the correct behavior of the new removal logic.
This commit is contained in:
Joe 2026-01-30 12:52:36 -06:00
parent 8c6aa36027
commit 439eb3f5f8
3 changed files with 346 additions and 6 deletions

View file

@ -174,10 +174,21 @@ impl JobThreadContext {
VfsEvent::Remove(path) => {
// MemoFS does not track parent removals yet, so we can canonicalize
// the parent path safely and then append the removed path's file name.
// However, if the parent was also deleted (e.g., when deleting a directory
// tree), canonicalize will fail - in that case, just skip this event.
let parent = path.parent().unwrap();
let file_name = path.file_name().unwrap();
let parent_normalized = self.vfs.canonicalize(parent).unwrap();
self.apply_patches(parent_normalized.join(file_name))
match self.vfs.canonicalize(parent) {
Ok(parent_normalized) => self.apply_patches(parent_normalized.join(file_name)),
Err(_) => {
// Parent directory was also deleted, skip this event
log::trace!(
"Skipping remove event for {:?} - parent no longer exists",
path
);
Vec::new()
}
}
}
_ => {
log::warn!("Unhandled VFS event: {:?}", event);