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:
parent
8f87b5637a
commit
04c04e8406
4 changed files with 44 additions and 17 deletions
|
@ -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::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue