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
This commit is contained in:
Lukas Wirth
2025-10-19 15:25:13 +00:00
committed by GitHub
parent 8f3f7232fb
commit 1b43a632dc
2 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -558,7 +558,14 @@ impl Fs for RealFs {
}
async fn open_handle(&self, path: &Path) -> Result<Arc<dyn FileHandle>> {
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<String> {
+2 -2
View File
@@ -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<ProjectEntryId, LocalRepositoryEntry>,
/// 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<Arc<dyn fs::FileHandle>>,
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;
}