From 843d299d9a4b2a8ec97707a18ea2524c9e13118c Mon Sep 17 00:00:00 2001 From: CharlesChen0823 Date: Tue, 7 May 2024 09:25:21 +0800 Subject: [PATCH] Windows: Fix canonicalize return UNC path (#11083) In Windows platform, using notify to watch file events. 1. in [notify windows implement](https://github.com/notify-rs/notify/blob/3df0f65152c8585cfb29d231c880b86b9164dcfd/notify/src/windows.rs#L344), we get the full file path, just with `path.join(file_path)`. 2. In [zed worktree start_backgroud_scan_tasks](https://github.com/zed-industries/zed/blob/d2569afe662be93c926eed1aeb2b17d050ba90b0/crates/worktree/src/worktree.rs#L679), `abs_path` is not unc path, so we get all file events with not unc path. 3. but in [zed worktree process_event](https://github.com/zed-industries/zed/blob/d2569afe662be93c926eed1aeb2b17d050ba90b0/crates/worktree/src/worktree.rs#L3619), we `strip_prefix` unc path all times, it will always print annoy error. @mikayla-maki I can't reopen pre closed pr #10501 . Release Notes: - N/A --- crates/worktree/src/worktree.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index b6ddb381a3c53..077f811ede6dc 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -673,7 +673,11 @@ fn start_background_scan_tasks( ) -> Vec> { let (scan_states_tx, mut scan_states_rx) = mpsc::unbounded(); let background_scanner = cx.background_executor().spawn({ - let abs_path = abs_path.to_path_buf(); + let abs_path = if cfg!(target_os = "windows") { + abs_path.canonicalize().expect("start background scan tasks failed for canonicalize path {abs_path}") + } else { + abs_path.to_path_buf() + }; let background = cx.background_executor().clone(); async move { let events = fs.watch(&abs_path, FS_WATCH_LATENCY).await;