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,4 +1,5 @@
use std::cmp;
use std::path::StripPrefixError;
use std::sync::{Arc, OnceLock};
use std::{
ffi::OsStr,
@ -113,6 +114,14 @@ impl SanitizedPath {
pub fn to_string(&self) -> String {
self.0.to_string_lossy().to_string()
}
pub fn join(&self, path: &Self) -> Self {
self.0.join(&path.0).into()
}
pub fn strip_prefix(&self, base: &Self) -> Result<&Path, StripPrefixError> {
self.0.strip_prefix(base.as_path())
}
}
impl From<SanitizedPath> for Arc<Path> {
@ -439,6 +448,14 @@ pub fn compare_paths(
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn replace_path_separator(path: &str) -> String {
#[cfg(target_os = "windows")]
return path.replace("/", std::path::MAIN_SEPARATOR_STR);
#[cfg(not(target_os = "windows"))]
return path.to_string();
}
#[cfg(test)]
mod tests {
use super::*;