Try not to use verbatim paths for UNC shares (#6824)

This commit is contained in:
Chris Denton
2022-10-22 17:51:52 +01:00
committed by GitHub
parent 3f555a6836
commit 89f3cbf318
6 changed files with 46 additions and 11 deletions

View File

@ -9,7 +9,7 @@ version = "0.70.1"
[dependencies]
dirs-next = "2.0.0"
dunce = "1.0.1"
omnipath = "0.1.1"
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
pwd = "1.3.1"
pwd = "1.3.1"

View File

@ -1,5 +1,7 @@
use std::path::{is_separator, Component, Path, PathBuf};
use super::helpers;
const EXPAND_STR: &str = if cfg!(windows) { r"..\" } else { "../" };
fn handle_dots_push(string: &mut String, count: u8) {
@ -108,7 +110,7 @@ pub fn expand_dots(path: impl AsRef<Path>) -> PathBuf {
_ => result.push(component),
});
dunce::simplified(&result).to_path_buf()
helpers::simiplified(&result)
}
#[cfg(test)]

View File

@ -2,6 +2,7 @@ use std::io;
use std::path::{Path, PathBuf};
use super::dots::{expand_dots, expand_ndots};
use super::helpers;
use super::tilde::expand_tilde;
// Join a path relative to another path. Paths starting with tilde are considered as absolute.
@ -30,7 +31,7 @@ fn canonicalize(path: impl AsRef<Path>) -> io::Result<PathBuf> {
let path = expand_tilde(path);
let path = expand_ndots(path);
dunce::canonicalize(path)
helpers::canonicalize(&path)
}
/// Resolve all symbolic links and all components (tilde, ., .., ...+) and return the path in its

View File

@ -1,3 +1,5 @@
#[cfg(windows)]
use omnipath::WinPathExt;
use std::path::PathBuf;
pub fn home_dir() -> Option<PathBuf> {
@ -7,3 +9,22 @@ pub fn home_dir() -> Option<PathBuf> {
pub fn config_dir() -> Option<PathBuf> {
dirs_next::config_dir()
}
#[cfg(windows)]
pub fn canonicalize(path: &std::path::Path) -> std::io::Result<std::path::PathBuf> {
path.canonicalize()?.to_winuser_path()
}
#[cfg(not(windows))]
pub fn canonicalize(path: &std::path::Path) -> std::io::Result<std::path::PathBuf> {
path.canonicalize()
}
#[cfg(windows)]
pub fn simiplified(path: &std::path::Path) -> PathBuf {
path.to_winuser_path()
.unwrap_or_else(|_| path.to_path_buf())
}
#[cfg(not(windows))]
pub fn simiplified(path: &std::path::Path) -> PathBuf {
path.to_path_buf()
}