Implement more tests, fix up removal

This commit is contained in:
Lucien Greathouse
2018-12-14 18:37:11 -08:00
parent 9516a1aeea
commit 308369b14f
2 changed files with 124 additions and 11 deletions

View File

@@ -93,16 +93,12 @@ impl Imfs {
debug_assert!(path.is_absolute());
debug_assert!(self.is_within_roots(path));
self.remove_item(path);
if let Some(parent_path) = path.parent() {
self.unlink_child(parent_path, path);
}
if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) {
for child_path in &directory.children {
self.path_removed(child_path)?;
}
}
Ok(())
}
@@ -117,6 +113,14 @@ impl Imfs {
Ok(())
}
fn remove_item(&mut self, path: &Path) {
if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) {
for child_path in &directory.children {
self.remove_item(child_path);
}
}
}
fn unlink_child(&mut self, parent: &Path, child: &Path) {
let parent_item = self.items.get_mut(parent);