diff --git a/Cargo.lock b/Cargo.lock index 5dcadf7e0..300096087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] name = "advapi32-sys" version = "0.2.0" @@ -434,6 +326,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "false" version = "0.0.1" +dependencies = [ + "uucore 0.0.1", +] [[package]] name = "filetime" @@ -1161,6 +1056,7 @@ version = "0.0.1" dependencies = [ "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)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "libstdbuf 0.0.1", "uucore 0.0.1", ] @@ -1336,6 +1232,9 @@ dependencies = [ [[package]] name = "true" version = "0.0.1" +dependencies = [ + "uucore 0.0.1", +] [[package]] name = "truncate" @@ -1458,6 +1357,114 @@ dependencies = [ "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]] name = "vec_map" version = "0.8.0" diff --git a/src/pwd/pwd.rs b/src/pwd/pwd.rs index 989d93b76..37a382503 100644 --- a/src/pwd/pwd.rs +++ b/src/pwd/pwd.rs @@ -15,11 +15,22 @@ extern crate getopts; extern crate uucore; use std::env; -use std::fs; +//use std::fs; +use std::path::{Path, PathBuf}; +use std::io; static NAME: &'static str = "pwd"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +pub fn absolute_path(path: &Path) -> io::Result { + 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) -> i32 { 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") { println!("{} {}", NAME, VERSION); } else { - let logical_path = env::current_dir().unwrap(); - if matches.opt_present("logical") { - println!("{}", logical_path.display()); - } else { - let physical_path = fs::canonicalize(&logical_path); - println!("{}", physical_path.unwrap().display()); - } + match env::current_dir() { + Ok(logical_path) => { + if matches.opt_present("logical") { + println!("{}", logical_path.display()); + } else { + 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