Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix symlinked root rename event handling (#58624)
Tianze Zhao693356221ec3
diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rsindex 13a65f6d944..868227a428a 100644--- a/crates/worktree/src/worktree.rs+++ b/crates/worktree/src/worktree.rs@@ -4508,6 +4508,10 @@ impl BackgroundScanner {&& let Ok(path) = RelPath::new(path, PathStyle::local()){path+ } else if let Ok(path) = abs_path.strip_prefix(&root_path)+ && let Ok(path) = RelPath::new(path, PathStyle::local())+ {+ path} else if let Some(path) = snapshot.external_canonical_to_relative.iter().find_map(|(canonical, relative)| {abs_pathdiff --git a/crates/worktree/tests/integration/worktree_tests.rs b/crates/worktree/tests/integration/worktree_tests.rsindex 661454c9b6a..9e848928c31 100644--- a/crates/worktree/tests/integration/worktree_tests.rs+++ b/crates/worktree/tests/integration/worktree_tests.rs@@ -476,6 +476,82 @@ async fn test_symlinks_pointing_outside(cx: &mut TestAppContext) {});}+#[gpui::test]+async fn test_renaming_subdir_under_symlinked_root_keeps_children(cx: &mut TestAppContext) {+ init_test(cx);+ let fs = FakeFs::new(cx.background_executor.clone());+ fs.insert_tree(+ "/target",+ json!({+ "file1.txt": "",+ "file2.log": "",+ "subdir-a": {+ "config.ini": "",+ },+ "subdir-b": {+ "nested": {+ "note.md": "",+ },+ },+ }),+ )+ .await;+ fs.create_symlink("/link".as_ref(), "/target".into())+ .await+ .unwrap();++ let tree = Worktree::local(+ Path::new("/link"),+ true,+ fs.clone(),+ Default::default(),+ true,+ WorktreeId::from_proto(0),+ &mut cx.to_async(),+ )+ .await+ .unwrap();++ cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())+ .await;++ fs.rename(+ Path::new("/link/subdir-a"),+ Path::new("/link/subdir-aa"),+ Default::default(),+ )+ .await+ .unwrap();++ wait_for_condition(cx, |cx| {+ tree.read_with(cx, |tree, _| {+ tree.entry_for_path(rel_path("subdir-a")).is_none()+ && tree+ .entry_for_path(rel_path("subdir-aa/config.ini"))+ .is_some()+ })+ })+ .await;++ tree.read_with(cx, |tree, _| {+ assert_eq!(+ tree.entries(true, 0)+ .map(|entry| entry.path.as_ref())+ .collect::<Vec<_>>(),+ vec![+ rel_path(""),+ rel_path("file1.txt"),+ rel_path("file2.log"),+ rel_path("subdir-aa"),+ rel_path("subdir-aa/config.ini"),+ rel_path("subdir-b"),+ rel_path("subdir-b/nested"),+ rel_path("subdir-b/nested/note.md"),+ ]+ );+ });+}+#[gpui::test]async fn test_symlinked_dir_inside_project(cx: &mut TestAppContext) {init_test(cx);