mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
pwd: fixes for UNC paths on Windows, match instead of plain unwrap
This commit is contained in:
parent
f8e24439c9
commit
6ef16b9221
2 changed files with 140 additions and 116 deletions
223
Cargo.lock
generated
223
Cargo.lock
generated
|
@ -1,111 +1,3 @@
|
||||||
[root]
|
|
||||||
name = "uutils"
|
|
||||||
version = "0.0.1"
|
|
||||||
dependencies = [
|
|
||||||
"arch 0.0.1",
|
|
||||||
"base32 0.0.1",
|
|
||||||
"base64 0.0.1",
|
|
||||||
"basename 0.0.1",
|
|
||||||
"cat 0.0.1",
|
|
||||||
"chgrp 0.0.1",
|
|
||||||
"chmod 0.0.1",
|
|
||||||
"chown 0.0.1",
|
|
||||||
"chroot 0.0.1",
|
|
||||||
"cksum 0.0.1",
|
|
||||||
"comm 0.0.1",
|
|
||||||
"cp 0.0.1",
|
|
||||||
"cut 0.0.1",
|
|
||||||
"date 0.0.1",
|
|
||||||
"dircolors 0.0.1",
|
|
||||||
"dirname 0.0.1",
|
|
||||||
"du 0.0.1",
|
|
||||||
"echo 0.0.1",
|
|
||||||
"env 0.0.1",
|
|
||||||
"expand 0.0.1",
|
|
||||||
"expr 0.0.1",
|
|
||||||
"factor 0.0.1",
|
|
||||||
"false 0.0.1",
|
|
||||||
"filetime 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"fmt 0.0.1",
|
|
||||||
"fold 0.0.1",
|
|
||||||
"groups 0.0.1",
|
|
||||||
"hashsum 0.0.1",
|
|
||||||
"head 0.0.1",
|
|
||||||
"hostid 0.0.1",
|
|
||||||
"hostname 0.0.1",
|
|
||||||
"id 0.0.1",
|
|
||||||
"install 0.0.1",
|
|
||||||
"kill 0.0.1",
|
|
||||||
"lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"link 0.0.1",
|
|
||||||
"ln 0.0.1",
|
|
||||||
"logname 0.0.1",
|
|
||||||
"ls 0.0.1",
|
|
||||||
"mkdir 0.0.1",
|
|
||||||
"mkfifo 0.0.1",
|
|
||||||
"mknod 0.0.1",
|
|
||||||
"mktemp 0.0.1",
|
|
||||||
"more 0.0.1",
|
|
||||||
"mv 0.0.1",
|
|
||||||
"nice 0.0.1",
|
|
||||||
"nl 0.0.1",
|
|
||||||
"nohup 0.0.1",
|
|
||||||
"nproc 0.0.1",
|
|
||||||
"numfmt 0.0.1",
|
|
||||||
"od 0.0.1",
|
|
||||||
"paste 0.0.1",
|
|
||||||
"pathchk 0.0.1",
|
|
||||||
"pinky 0.0.1",
|
|
||||||
"printenv 0.0.1",
|
|
||||||
"printf 0.0.1",
|
|
||||||
"ptx 0.0.1",
|
|
||||||
"pwd 0.0.1",
|
|
||||||
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"readlink 0.0.1",
|
|
||||||
"realpath 0.0.1",
|
|
||||||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"relpath 0.0.1",
|
|
||||||
"rm 0.0.1",
|
|
||||||
"rmdir 0.0.1",
|
|
||||||
"seq 0.0.1",
|
|
||||||
"shred 0.0.1",
|
|
||||||
"shuf 0.0.1",
|
|
||||||
"sleep 0.0.1",
|
|
||||||
"sort 0.0.1",
|
|
||||||
"split 0.0.1",
|
|
||||||
"stat 0.0.1",
|
|
||||||
"stdbuf 0.0.1",
|
|
||||||
"sum 0.0.1",
|
|
||||||
"sync 0.0.1",
|
|
||||||
"tac 0.0.1",
|
|
||||||
"tail 0.0.1",
|
|
||||||
"tee 0.0.1",
|
|
||||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"test 0.0.1",
|
|
||||||
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"timeout 0.0.1",
|
|
||||||
"touch 0.0.1",
|
|
||||||
"tr 0.0.1",
|
|
||||||
"true 0.0.1",
|
|
||||||
"truncate 0.0.1",
|
|
||||||
"tsort 0.0.1",
|
|
||||||
"tty 0.0.1",
|
|
||||||
"uname 0.0.1",
|
|
||||||
"unexpand 0.0.1",
|
|
||||||
"unindent 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"uniq 0.0.1",
|
|
||||||
"unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"unlink 0.0.1",
|
|
||||||
"uptime 0.0.1",
|
|
||||||
"users 0.0.1",
|
|
||||||
"uucore 0.0.1",
|
|
||||||
"wc 0.0.1",
|
|
||||||
"who 0.0.1",
|
|
||||||
"whoami 0.0.1",
|
|
||||||
"yes 0.0.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "advapi32-sys"
|
name = "advapi32-sys"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -434,6 +326,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "false"
|
name = "false"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"uucore 0.0.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
|
@ -1161,6 +1056,7 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libstdbuf 0.0.1",
|
"libstdbuf 0.0.1",
|
||||||
"uucore 0.0.1",
|
"uucore 0.0.1",
|
||||||
]
|
]
|
||||||
|
@ -1336,6 +1232,9 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "true"
|
name = "true"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"uucore 0.0.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "truncate"
|
name = "truncate"
|
||||||
|
@ -1458,6 +1357,114 @@ dependencies = [
|
||||||
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uutils"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"arch 0.0.1",
|
||||||
|
"base32 0.0.1",
|
||||||
|
"base64 0.0.1",
|
||||||
|
"basename 0.0.1",
|
||||||
|
"cat 0.0.1",
|
||||||
|
"chgrp 0.0.1",
|
||||||
|
"chmod 0.0.1",
|
||||||
|
"chown 0.0.1",
|
||||||
|
"chroot 0.0.1",
|
||||||
|
"cksum 0.0.1",
|
||||||
|
"comm 0.0.1",
|
||||||
|
"cp 0.0.1",
|
||||||
|
"cut 0.0.1",
|
||||||
|
"date 0.0.1",
|
||||||
|
"dircolors 0.0.1",
|
||||||
|
"dirname 0.0.1",
|
||||||
|
"du 0.0.1",
|
||||||
|
"echo 0.0.1",
|
||||||
|
"env 0.0.1",
|
||||||
|
"expand 0.0.1",
|
||||||
|
"expr 0.0.1",
|
||||||
|
"factor 0.0.1",
|
||||||
|
"false 0.0.1",
|
||||||
|
"filetime 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"fmt 0.0.1",
|
||||||
|
"fold 0.0.1",
|
||||||
|
"groups 0.0.1",
|
||||||
|
"hashsum 0.0.1",
|
||||||
|
"head 0.0.1",
|
||||||
|
"hostid 0.0.1",
|
||||||
|
"hostname 0.0.1",
|
||||||
|
"id 0.0.1",
|
||||||
|
"install 0.0.1",
|
||||||
|
"kill 0.0.1",
|
||||||
|
"lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"link 0.0.1",
|
||||||
|
"ln 0.0.1",
|
||||||
|
"logname 0.0.1",
|
||||||
|
"ls 0.0.1",
|
||||||
|
"mkdir 0.0.1",
|
||||||
|
"mkfifo 0.0.1",
|
||||||
|
"mknod 0.0.1",
|
||||||
|
"mktemp 0.0.1",
|
||||||
|
"more 0.0.1",
|
||||||
|
"mv 0.0.1",
|
||||||
|
"nice 0.0.1",
|
||||||
|
"nl 0.0.1",
|
||||||
|
"nohup 0.0.1",
|
||||||
|
"nproc 0.0.1",
|
||||||
|
"numfmt 0.0.1",
|
||||||
|
"od 0.0.1",
|
||||||
|
"paste 0.0.1",
|
||||||
|
"pathchk 0.0.1",
|
||||||
|
"pinky 0.0.1",
|
||||||
|
"printenv 0.0.1",
|
||||||
|
"printf 0.0.1",
|
||||||
|
"ptx 0.0.1",
|
||||||
|
"pwd 0.0.1",
|
||||||
|
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"readlink 0.0.1",
|
||||||
|
"realpath 0.0.1",
|
||||||
|
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"relpath 0.0.1",
|
||||||
|
"rm 0.0.1",
|
||||||
|
"rmdir 0.0.1",
|
||||||
|
"seq 0.0.1",
|
||||||
|
"shred 0.0.1",
|
||||||
|
"shuf 0.0.1",
|
||||||
|
"sleep 0.0.1",
|
||||||
|
"sort 0.0.1",
|
||||||
|
"split 0.0.1",
|
||||||
|
"stat 0.0.1",
|
||||||
|
"stdbuf 0.0.1",
|
||||||
|
"sum 0.0.1",
|
||||||
|
"sync 0.0.1",
|
||||||
|
"tac 0.0.1",
|
||||||
|
"tail 0.0.1",
|
||||||
|
"tee 0.0.1",
|
||||||
|
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"test 0.0.1",
|
||||||
|
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"timeout 0.0.1",
|
||||||
|
"touch 0.0.1",
|
||||||
|
"tr 0.0.1",
|
||||||
|
"true 0.0.1",
|
||||||
|
"truncate 0.0.1",
|
||||||
|
"tsort 0.0.1",
|
||||||
|
"tty 0.0.1",
|
||||||
|
"uname 0.0.1",
|
||||||
|
"unexpand 0.0.1",
|
||||||
|
"unindent 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"uniq 0.0.1",
|
||||||
|
"unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"unlink 0.0.1",
|
||||||
|
"uptime 0.0.1",
|
||||||
|
"users 0.0.1",
|
||||||
|
"uucore 0.0.1",
|
||||||
|
"wc 0.0.1",
|
||||||
|
"who 0.0.1",
|
||||||
|
"whoami 0.0.1",
|
||||||
|
"yes 0.0.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|
|
@ -15,11 +15,22 @@ extern crate getopts;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
//use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::io;
|
||||||
|
|
||||||
static NAME: &'static str = "pwd";
|
static NAME: &'static str = "pwd";
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
|
||||||
|
let path_buf = path.canonicalize()?;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let path_buf = Path::new(path_buf.as_path().to_string_lossy().trim_left_matches(r"\\?\")).to_path_buf();
|
||||||
|
|
||||||
|
Ok(path_buf)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut opts = getopts::Options::new();
|
let mut opts = getopts::Options::new();
|
||||||
|
|
||||||
|
@ -46,13 +57,19 @@ Print the full filename of the current working directory.", NAME, VERSION);
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("{} {}", NAME, VERSION);
|
println!("{} {}", NAME, VERSION);
|
||||||
} else {
|
} else {
|
||||||
let logical_path = env::current_dir().unwrap();
|
match env::current_dir() {
|
||||||
if matches.opt_present("logical") {
|
Ok(logical_path) => {
|
||||||
println!("{}", logical_path.display());
|
if matches.opt_present("logical") {
|
||||||
} else {
|
println!("{}", logical_path.display());
|
||||||
let physical_path = fs::canonicalize(&logical_path);
|
} else {
|
||||||
println!("{}", physical_path.unwrap().display());
|
match absolute_path(&logical_path) {
|
||||||
}
|
Ok(physical_path) => println!("{}", physical_path.display()),
|
||||||
|
Err(e) => crash!(1, "failed to get absolute path {}", e)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => crash!(1, "failed to get current directory {}", e)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue