From 126bbba17aa2a7937bbbfd902752884df3f683a1 Mon Sep 17 00:00:00 2001 From: Tracy Date: Sun, 4 Jun 2023 10:03:01 -0400 Subject: [PATCH] pwd: Fixes #4855 (#4937) Based on testing with GNU's pwd, it seems like the -P flag should take precedence over the use of the POSIXLY_CORRECT flag. Co-authored-by: Terts Diepraam --- src/uu/pwd/src/pwd.rs | 4 +++- tests/by-util/test_pwd.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 7af194872..9e04dd38b 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -115,7 +115,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // if POSIXLY_CORRECT is set, we want to a logical resolution. // This produces a different output when doing mkdir -p a/b && ln -s a/b c && cd c && pwd // We should get c in this case instead of a/b at the end of the path - let cwd = if matches.get_flag(OPT_LOGICAL) || env::var("POSIXLY_CORRECT").is_ok() { + let cwd = if matches.get_flag(OPT_PHYSICAL) { + physical_path() + } else if matches.get_flag(OPT_LOGICAL) || env::var("POSIXLY_CORRECT").is_ok() { logical_path() } else { physical_path() diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index 076e72089..1e43f5be6 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -116,7 +116,7 @@ fn test_symlinked_default_posix_p() { .env("POSIXLY_CORRECT", "1") .arg("-P") .succeeds() - .stdout_is(env.symdir + "\n"); + .stdout_is(env.subdir + "\n"); } #[cfg(not(windows))]