Skip to content

add support for windows UNC path #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -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> {
let path = path.as_ref();
let base_path;
let unc_path;

let mut components = path.components().peekable();
let mut stack = Vec::new();
@@ -309,6 +310,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) => {
@@ -331,6 +335,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) => {