From f7b2713b77338bd54c341104121413fe885fc91c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 21 Mar 2023 15:41:24 -0700 Subject: [PATCH] Fix error in joining empty paths --- crates/project/src/worktree.rs | 61 +++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 33714e762f..90da3253d5 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -809,31 +809,32 @@ impl LocalWorktree { cx: &mut ModelContext, ) -> Option>> { let entry = self.entry_for_id(entry_id)?.clone(); - let path = entry.path.clone(); - let abs_path = self.absolutize(&path); - let (tx, mut rx) = barrier::channel(); + let abs_path = self.abs_path.clone(); + let fs = self.fs.clone(); - let delete = cx.background().spawn({ - let abs_path = abs_path.clone(); - let fs = self.fs.clone(); - async move { - if entry.is_file() { - fs.remove_file(&abs_path, Default::default()).await - } else { - fs.remove_dir( - &abs_path, - RemoveOptions { - recursive: true, - ignore_if_not_exists: false, - }, - ) - .await - } + let delete = cx.background().spawn(async move { + let mut abs_path = fs.canonicalize(&abs_path).await?; + if entry.path.file_name().is_some() { + abs_path = abs_path.join(&entry.path); } + if entry.is_file() { + fs.remove_file(&abs_path, Default::default()).await?; + } else { + fs.remove_dir( + &abs_path, + RemoveOptions { + recursive: true, + ignore_if_not_exists: false, + }, + ) + .await?; + } + anyhow::Ok(abs_path) }); Some(cx.spawn(|this, mut cx| async move { - delete.await?; + let abs_path = delete.await?; + let (tx, mut rx) = barrier::channel(); this.update(&mut cx, |this, _| { this.as_local_mut() .unwrap() @@ -912,15 +913,23 @@ impl LocalWorktree { cx: &mut ModelContext, ) -> Task> { let fs = self.fs.clone(); - let abs_path = self.abs_path.clone(); + let abs_root_path = self.abs_path.clone(); let path_changes_tx = self.path_changes_tx.clone(); cx.spawn_weak(move |this, mut cx| async move { - let abs_path = fs.canonicalize(&abs_path).await?; - let paths = if let Some(old_path) = old_path { - vec![abs_path.join(&path), abs_path.join(&old_path)] + let abs_path = fs.canonicalize(&abs_root_path).await?; + let mut paths = Vec::with_capacity(2); + paths.push(if path.file_name().is_some() { + abs_path.join(&path) } else { - vec![abs_path.join(&path)] - }; + abs_path.clone() + }); + if let Some(old_path) = old_path { + paths.push(if old_path.file_name().is_some() { + abs_path.join(&old_path) + } else { + abs_path.clone() + }); + } let (tx, mut rx) = barrier::channel(); path_changes_tx.unbounded_send((paths, tx)).unwrap();