From 1b43a632dc488a62c0ccc87316b118468f701bb0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 19 Oct 2025 17:25:13 +0200 Subject: [PATCH] fs: Fix `RealFs::open_handle` implementation for directories on windows (#40639) Release Notes: - Fixed worktree names not updating when renaming the root folder on windows --- crates/fs/src/fs.rs | 9 ++++++++- crates/worktree/src/worktree.rs | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index 9907d0dcbde489b4f4de57133baf299ad0be14a1..9fe9e53eaacc864ad66248131813e305fd5bc172 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -558,7 +558,14 @@ impl Fs for RealFs { } async fn open_handle(&self, path: &Path) -> Result> { - Ok(Arc::new(std::fs::File::open(path)?)) + let mut options = std::fs::OpenOptions::new(); + options.read(true); + #[cfg(windows)] + { + use std::os::windows::fs::OpenOptionsExt; + options.custom_flags(windows::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS.0); + } + Ok(Arc::new(options.open(path)?)) } async fn load(&self, path: &Path) -> Result { diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index 3fa271a37ac014e046b4e5a98ae780d45a66743c..447dc0eeb5fe69aa8a936a5850e788d315a69bac 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -236,7 +236,7 @@ pub struct LocalSnapshot { /// All of the git repositories in the worktree, indexed by the project entry /// id of their parent directory. git_repositories: TreeMap, - /// The file handle of the worktree root. `None` if the worktree is a directory. + /// The file handle of the worktree root /// (so we can find it after it's been moved) root_file_handle: Option>, executor: BackgroundExecutor, @@ -3830,7 +3830,7 @@ impl BackgroundScanner { .unbounded_send(ScanState::RootUpdated { new_path }) .ok(); } else { - log::warn!("root path could not be canonicalized: {}", err); + log::warn!("root path could not be canonicalized: {:#}", err); } return; }