diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index 25ade0bca4..c62f60ea20 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -258,51 +258,50 @@ impl Snapshot { } fn remove_path(&mut self, path: &Path) { - if let Some(mut parent_entry) = path.parent().and_then(|p| self.entry_for_path(p).cloned()) - { - let mut edits = Vec::new(); + let mut parent_entry = match path.parent().and_then(|p| self.entry_for_path(p).cloned()) { + Some(e) => e, + None => return, + }; - 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())); - } + 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) { - entry_inode = None; - } - - *children = new_children.into(); - edits.push(Edit::Insert(parent_entry)); - } else { - unreachable!(); } - if let Some(entry_inode) = entry_inode { - // Recursively remove the orphaned nodes' descendants. - let mut descendant_stack = Vec::new(); - descendant_stack.push((entry_inode, parent_inode)); - while let Some((inode, parent_inode)) = descendant_stack.pop() { - if let Some(entry) = self.entries.get(&inode) { - if entry.parent() == Some(parent_inode) { - edits.push(Edit::Remove(inode)); - if let Entry::Dir { children, .. } = entry { - descendant_stack - .extend(children.iter().map(|c| (c.0, entry.inode()))); - } + if new_children.iter().any(|c| Some(c.0) == entry_inode) { + entry_inode = None; + } + + *children = new_children.into(); + edits.push(Edit::Insert(parent_entry)); + } else { + unreachable!(); + } + + if let Some(entry_inode) = entry_inode { + let mut descendant_stack = Vec::new(); + descendant_stack.push((entry_inode, parent_inode)); + while let Some((inode, parent_inode)) = descendant_stack.pop() { + if let Some(entry) = self.entries.get(&inode) { + if entry.parent() == Some(parent_inode) { + edits.push(Edit::Remove(inode)); + if let Entry::Dir { children, .. } = entry { + descendant_stack.extend(children.iter().map(|c| (c.0, entry.inode()))); } } } } - - self.entries.edit(edits); } + + self.entries.edit(edits); } fn fmt_entry( @@ -372,19 +371,19 @@ impl FileHandle { #[derive(Clone, Debug)] pub enum Entry { Dir { - parent: Option, inode: u64, + parent: Option, is_symlink: bool, is_ignored: bool, children: Arc<[(u64, Arc)]>, pending: bool, }, File { - parent: Option, - path: PathEntry, inode: u64, + parent: Option, is_symlink: bool, is_ignored: bool, + path: PathEntry, }, }