This commit is contained in:
PaysanCorrezien 2025-09-23 18:55:56 +02:00 committed by GitHub
commit cce4ac7413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -273,6 +273,7 @@ pub fn path_to_str(path: &impl AsRef<Path>) -> Result<&str> {
pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
let path = path.as_ref();
let base_path;
let unc_path;
let mut components = path.components().peekable();
let mut stack = Vec::new();
@ -314,6 +315,9 @@ pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
Ok(path)
}
fn get_network_path(server: &OsStr, share: &OsStr) -> PathBuf {
format!(r"\\{}\{}", server.to_string_lossy(), share.to_string_lossy()).into()
}
match components.peek() {
Some(Component::Prefix(prefix)) => match prefix.kind() {
Prefix::Disk(drive_letter) => {
@ -336,6 +340,28 @@ pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
base_path = get_drive_path(drive_letter);
stack.extend(base_path.components());
}
Prefix::VerbatimUNC(server, share) => {
unc_path = get_network_path(server, share);
components.next(); // Consume the Prefix component
if components.peek() == Some(&Component::RootDir) {
components.next();
}
stack.extend(unc_path.components());
}
Prefix::UNC(server, share) => {
unc_path = get_network_path(server, share);
components.next(); // Consume the Prefix component
if components.peek() == Some(&Component::RootDir) {
components.next();
}
stack.extend(unc_path.components());
}
_ => bail!("invalid path: {}", path.display()),
},
Some(Component::RootDir) => {