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

@ -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()
}