1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 23:17:46 +00:00

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.
This commit is contained in:
Roy Ivy III 2020-01-02 05:10:47 +00:00
parent 2792d85865
commit 667ed39ece
2 changed files with 4 additions and 2 deletions

View file

@ -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 = []

View file

@ -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<P: AsRef<Path>>(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();