mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Try not to use verbatim paths for UNC shares (#6824)
This commit is contained in:
@ -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"
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user