дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
On network shares every stat is a round trip, and several paths did one per file or per ancestor. Directory listings take kind, size and mtime from the listing itself; Project view expansion lists through the project watcher and reuses its ignore rules and repository root; root detection probes Unity and virtual-env markers only when their names appear; the Gradle build walk is reused for 30 seconds on hot paths; project_roots runs off the IPC thread; index warm start checks files against one listing per folder, in parallel, and stops when the project closes; git status on network paths compares only mtime and size. Co-authored-by: wildcatDownstairs <[email protected]>
54 рядки
1.8 KiB
Rust
54 рядки
1.8 KiB
Rust
//! Whether a path is on a network file system, where every stat is a round trip to a server.
|
|
|
|
use std::path::{Component, Path, Prefix};
|
|
|
|
/// A UNC path (`\\server\share`, `\\wsl.localhost\…`) or a drive letter mapped to a network
|
|
/// share (`Z:\`). Always `false` off Windows: there a mount point is not visible in the path.
|
|
pub fn is_network_path(path: &Path) -> bool {
|
|
match path.components().next() {
|
|
Some(Component::Prefix(prefix)) => match prefix.kind() {
|
|
Prefix::UNC(..) | Prefix::VerbatimUNC(..) => true,
|
|
Prefix::Disk(letter) | Prefix::VerbatimDisk(letter) => is_remote_drive(letter),
|
|
_ => false,
|
|
},
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
fn is_remote_drive(letter: u8) -> bool {
|
|
use windows_sys::Win32::Storage::FileSystem::GetDriveTypeW;
|
|
/// `DRIVE_REMOTE` (WindowsProgramming).
|
|
const DRIVE_REMOTE: u32 = 4;
|
|
let root = [u16::from(letter), u16::from(b':'), u16::from(b'\\'), 0];
|
|
// SAFETY: `root` is a NUL-terminated wide string that outlives the call.
|
|
unsafe { GetDriveTypeW(root.as_ptr()) == DRIVE_REMOTE }
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
fn is_remote_drive(_letter: u8) -> bool {
|
|
false
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::is_network_path;
|
|
use std::path::Path;
|
|
|
|
#[test]
|
|
fn unc_paths_are_on_the_network() {
|
|
if cfg!(windows) {
|
|
assert!(is_network_path(Path::new(r"\\server\share\repo")));
|
|
assert!(is_network_path(Path::new(r"\\?\UNC\server\share\repo")));
|
|
assert!(is_network_path(Path::new(r"\\wsl.localhost\Ubuntu\home")));
|
|
}
|
|
assert!(!is_network_path(Path::new("relative/path")));
|
|
}
|
|
|
|
#[test]
|
|
fn a_local_directory_is_not() {
|
|
let dir = std::env::temp_dir();
|
|
assert!(!is_network_path(&dir), "{}", dir.display());
|
|
}
|
|
}
|