From 667ed39ece104ba0adaabb319d03841afb523934 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 2 Jan 2020 05:10:47 +0000 Subject: [PATCH] fix uucore::fs for windows - standardize the return value of `std::env::current_dir()` by using `canonicalize()` .# [why] `std::env::current_dir()` will, in some situations on windows hosts, return "short"-type paths (eg, "C:\Progra~1\..."). Using `canonicalize()` transforms the path in a standard long form but may also require removing a leading "\\?\" prefix. --- src/uucore/Cargo.toml | 2 +- src/uucore/src/fs.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 66bed3510..611be8af9 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -16,6 +16,7 @@ travis-ci = { repository = "uutils/uucore" } appveyor = { repository = "uutils/uucore" } [dependencies] +dunce = "1.0.0" getopts = "0.2.18" failure = { version = "0.1.1", optional = true } failure_derive = { version = "0.1.1", optional = true } @@ -43,4 +44,3 @@ entries = ["libc"] zero-copy = ["nix", "libc", "lazy_static", "platform-info"] wide = [] default = [] - diff --git a/src/uucore/src/fs.rs b/src/uucore/src/fs.rs index 65819afcc..39d4b1f5a 100644 --- a/src/uucore/src/fs.rs +++ b/src/uucore/src/fs.rs @@ -6,6 +6,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +#[cfg(windows)] +extern crate dunce; #[cfg(target_os = "redox")] extern crate termion; @@ -101,7 +103,7 @@ pub fn canonicalize>(original: P, can_mode: CanonicalizeMode) -> let original = if original.is_absolute() { original.to_path_buf() } else { - env::current_dir().unwrap().join(original) + dunce::canonicalize(env::current_dir().unwrap()).unwrap().join(original) }; let mut result = PathBuf::new();