From 51fc2d7564b29de22936e8ca4a73883aeca77662 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 1 Dec 2023 16:27:05 +0100 Subject: [PATCH] ls: ignore value of POSIXLY_CORRECT --- src/uu/ls/src/ls.rs | 10 +++------- tests/by-util/test_ls.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 3745cfc9d..f645e31d3 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -20,7 +20,7 @@ use std::os::windows::fs::MetadataExt; use std::{ cmp::Reverse, error::Error, - ffi::{OsStr, OsString}, + ffi::OsString, fmt::{Display, Write as FmtWrite}, fs::{self, DirEntry, FileType, Metadata, ReadDir}, io::{stdout, BufWriter, ErrorKind, Stdout, Write}, @@ -792,12 +792,8 @@ impl Config { None } } - } else if let Some(pc) = env_var_posixly_correct { - if pc.as_os_str() == OsStr::new("true") || pc == OsStr::new("1") { - Some(POSIXLY_CORRECT_BLOCK_SIZE) - } else { - None - } + } else if env_var_posixly_correct.is_some() { + Some(POSIXLY_CORRECT_BLOCK_SIZE) } else { None }; diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 19a3f5578..fcd57170d 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3828,3 +3828,30 @@ fn test_ls_cf_output_should_be_delimited_by_tab() { .succeeds() .stdout_is("a2345/\tb/\n"); } + +#[cfg(all(unix, feature = "dd"))] +#[test] +fn test_posixly_correct() { + let scene = TestScenario::new(util_name!()); + + scene + .ccmd("dd") + .arg("if=/dev/zero") + .arg("of=file") + .arg("bs=1024") + .arg("count=1") + .succeeds(); + + scene + .ucmd() + .arg("-s") + .succeeds() + .stdout_contains_line("total 4"); + + scene + .ucmd() + .arg("-s") + .env("POSIXLY_CORRECT", "some_value") + .succeeds() + .stdout_contains_line("total 8"); +}