From f8e24439c9661ab5de46b1aa1458fe72d91dd251 Mon Sep 17 00:00:00 2001 From: Mikhail Pukhlikov Date: Fri, 29 Sep 2017 17:34:21 +0400 Subject: [PATCH] pwd: add support for -L and -P options --- src/pwd/pwd.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pwd/pwd.rs b/src/pwd/pwd.rs index 16d082b25..989d93b76 100644 --- a/src/pwd/pwd.rs +++ b/src/pwd/pwd.rs @@ -15,6 +15,7 @@ extern crate getopts; extern crate uucore; use std::env; +use std::fs; static NAME: &'static str = "pwd"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -24,6 +25,8 @@ pub fn uumain(args: Vec) -> i32 { opts.optflag("", "help", "display this help and exit"); opts.optflag("", "version", "output version information and exit"); + opts.optflag("L", "logical", "use PWD from environment, even if it contains symlinks"); + opts.optflag("P", "physical", "avoid all symlinks"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -43,7 +46,13 @@ Print the full filename of the current working directory.", NAME, VERSION); } else if matches.opt_present("version") { println!("{} {}", NAME, VERSION); } else { - println!("{}", env::current_dir().unwrap().display()); + 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()); + } } 0