Merge pull request #4085 from sylvestre/pwd-posix

pwd: support the env variable 'POSIXLY_CORRECT'
This commit is contained in:
Terts Diepraam 2022-10-26 23:19:27 +02:00 committed by GitHub
commit 3cb1b9466a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -126,7 +126,10 @@ fn logical_path() -> io::Result<PathBuf> {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;
let cwd = if matches.get_flag(OPT_LOGICAL) {
// 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() {
logical_path()
} else {
physical_path()

View file

@ -90,6 +90,35 @@ fn test_symlinked_default() {
env.ucmd.succeeds().stdout_is(env.subdir + "\n");
}
#[test]
fn test_symlinked_default_posix() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.succeeds()
.stdout_is(env.symdir.clone() + "\n");
}
#[test]
fn test_symlinked_default_posix_l() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.arg("-L")
.succeeds()
.stdout_is(env.symdir + "\n");
}
#[test]
fn test_symlinked_default_posix_p() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.arg("-P")
.succeeds()
.stdout_is(env.symdir + "\n");
}
#[cfg(not(windows))]
pub mod untrustworthy_pwd_var {
use std::path::Path;