mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 14:52:41 +00:00
Merge pull request #4085 from sylvestre/pwd-posix
pwd: support the env variable 'POSIXLY_CORRECT'
This commit is contained in:
commit
3cb1b9466a
2 changed files with 33 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue