mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-28 01:07:09 +00:00
WIP
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
fd8125b22c
commit
031d5ac7d4
1 changed files with 23 additions and 33 deletions
|
@ -299,45 +299,33 @@ impl Snapshot {
|
||||||
self.entries.edit(edits);
|
self.entries.edit(edits);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_entry(&mut self, path: &Path) {
|
fn remove_subtree(&mut self, subtree_inode: u64) {
|
||||||
let mut parent_entry = match path.parent().and_then(|p| self.entry_for_path(p).cloned()) {
|
let entry = self.entries.get(&subtree_inode).unwrap();
|
||||||
Some(e) => e,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut edits = Vec::new();
|
let mut edits = Vec::new();
|
||||||
let parent_inode = parent_entry.inode();
|
|
||||||
let mut entry_inode = None;
|
|
||||||
if let Entry::Dir { children, .. } = &mut parent_entry {
|
|
||||||
let mut new_children = Vec::new();
|
|
||||||
for (child_inode, child_name) in children.as_ref() {
|
|
||||||
if Some(child_name.as_ref()) == path.file_name() {
|
|
||||||
entry_inode = Some(*child_inode);
|
|
||||||
} else {
|
|
||||||
new_children.push((*child_inode, child_name.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if new_children.iter().any(|c| Some(c.0) == entry_inode) {
|
// Update the parent entry to not include this subtree as one of its children.
|
||||||
entry_inode = None;
|
if let Some(parent_inode) = entry.parent() {
|
||||||
|
let mut parent_entry = self.entries.get(&parent_inode).unwrap().clone();
|
||||||
|
if let Entry::Dir { children, .. } = &mut parent_entry {
|
||||||
|
*children = children
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(child_inode, _)| *child_inode != subtree_inode)
|
||||||
|
.cloned()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into();
|
||||||
|
} else {
|
||||||
|
unreachable!("parent was not a directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
*children = new_children.into();
|
|
||||||
edits.push(Edit::Insert(parent_entry));
|
edits.push(Edit::Insert(parent_entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(entry_inode) = entry_inode {
|
// Remove all descendant entries for this subtree.
|
||||||
let mut descendant_stack = Vec::new();
|
let mut stack = vec![subtree_inode];
|
||||||
descendant_stack.push((entry_inode, parent_inode));
|
while let Some(inode) = stack.pop() {
|
||||||
while let Some((inode, parent_inode)) = descendant_stack.pop() {
|
edits.push(Edit::Remove(inode));
|
||||||
if let Some(entry) = self.entries.get(&inode) {
|
if let Entry::Dir { children, .. } = self.entries.get(&inode).unwrap() {
|
||||||
if entry.parent() == Some(parent_inode) {
|
stack.extend(children.iter().map(|(child_inode, _)| *child_inode));
|
||||||
edits.push(Edit::Remove(inode));
|
|
||||||
if let Entry::Dir { children, .. } = entry {
|
|
||||||
descendant_stack.extend(children.iter().map(|c| (c.0, entry.inode())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,7 +717,9 @@ impl BackgroundScanner {
|
||||||
paths.next();
|
paths.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot.remove_entry(&relative_path);
|
if let Some(inode) = snapshot.inode_for_path(&relative_path) {
|
||||||
|
snapshot.remove_subtree(inode);
|
||||||
|
}
|
||||||
|
|
||||||
match self.fs_entry_for_path(&root_path, &path) {
|
match self.fs_entry_for_path(&root_path, &path) {
|
||||||
Ok(Some((fs_entry, ignore))) => {
|
Ok(Some((fs_entry, ignore))) => {
|
||||||
|
|
Loading…
Reference in a new issue