windows: Fix FS-related issues (#23369)

I've noticed an occasional error: `ignoring event C:\some\path\to\file
outside of root path \\?\C:\some\path`. This happens because UNC paths
always fail to match with non-UNC paths during operations like
`strip_prefix` or `starts_with`. To address this, I changed the types of
some key parameters to `SanitizedPath`. With this adjustment, FS events
are now correctly identified, and under the changes in this PR, the
`test_rescan_and_remote_updates` test also passes successfully on
Windows.

Release Notes:

- N/A
This commit is contained in:
张小白 2025-01-21 14:19:23 +08:00 committed by GitHub
parent 8f87b5637a
commit 04c04e8406
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 17 deletions

View file

@ -1,7 +1,7 @@
use notify::EventKind;
use parking_lot::Mutex;
use std::sync::{Arc, OnceLock};
use util::ResultExt;
use util::{paths::SanitizedPath, ResultExt};
use crate::{PathEvent, PathEventKind, Watcher};
@ -24,7 +24,7 @@ impl FsWatcher {
impl Watcher for FsWatcher {
fn add(&self, path: &std::path::Path) -> gpui::Result<()> {
let root_path = path.to_path_buf();
let root_path = SanitizedPath::from(path);
let tx = self.tx.clone();
let pending_paths = self.pending_path_events.clone();
@ -44,8 +44,9 @@ impl Watcher for FsWatcher {
.paths
.iter()
.filter_map(|event_path| {
let event_path = SanitizedPath::from(event_path);
event_path.starts_with(&root_path).then(|| PathEvent {
path: event_path.clone(),
path: event_path.as_path().to_path_buf(),
kind,
})
})