add support for windows UNC path
This commit is contained in:
parent
3022cf3686
commit
bc0d7dc0f7
26
src/util.rs
26
src/util.rs
|
|
@ -268,6 +268,7 @@ pub fn path_to_str(path: &impl AsRef<Path>) -> Result<&str> {
|
||||||
pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
|
pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let base_path;
|
let base_path;
|
||||||
|
let unc_path;
|
||||||
|
|
||||||
let mut components = path.components().peekable();
|
let mut components = path.components().peekable();
|
||||||
let mut stack = Vec::new();
|
let mut stack = Vec::new();
|
||||||
|
|
@ -309,6 +310,9 @@ pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
|
||||||
Ok(path)
|
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() {
|
match components.peek() {
|
||||||
Some(Component::Prefix(prefix)) => match prefix.kind() {
|
Some(Component::Prefix(prefix)) => match prefix.kind() {
|
||||||
Prefix::Disk(drive_letter) => {
|
Prefix::Disk(drive_letter) => {
|
||||||
|
|
@ -331,6 +335,28 @@ pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
|
||||||
base_path = get_drive_path(drive_letter);
|
base_path = get_drive_path(drive_letter);
|
||||||
stack.extend(base_path.components());
|
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()),
|
_ => bail!("invalid path: {}", path.display()),
|
||||||
},
|
},
|
||||||
Some(Component::RootDir) => {
|
Some(Component::RootDir) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue