From a6d15d67caf13c86aa2973ea45a7ed7758c8f50b Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 1 Dec 2023 15:15:44 +0100 Subject: [PATCH 1/3] ls: cleanup "spell-checker:ignore" entries --- src/uu/ls/src/ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index cba9cdf5375..6e7fe405b16 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (ToDO) cpio svgz webm somegroup nlink rmvb xspf tabsize dired subdired dtype +// spell-checker:ignore (ToDO) somegroup nlink tabsize dired subdired dtype use clap::{ builder::{NonEmptyStringValueParser, ValueParser}, From c77d389f5b93399bdeb6007f24d745c94e64f454 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 1 Dec 2023 16:19:13 +0100 Subject: [PATCH 2/3] ls: improve some var names related to block sizes --- src/uu/ls/src/ls.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 6e7fe405b16..3745cfc9df3 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -741,14 +741,14 @@ impl Config { let mut needs_color = extract_color(options); - let cmd_line_bs = options.get_one::(options::size::BLOCK_SIZE); - let opt_si = cmd_line_bs.is_some() + let opt_block_size = options.get_one::(options::size::BLOCK_SIZE); + let opt_si = opt_block_size.is_some() && options .get_one::(options::size::BLOCK_SIZE) .unwrap() .eq("si") || options.get_flag(options::size::SI); - let opt_hr = (cmd_line_bs.is_some() + let opt_hr = (opt_block_size.is_some() && options .get_one::(options::size::BLOCK_SIZE) .unwrap() @@ -756,9 +756,9 @@ impl Config { || options.get_flag(options::size::HUMAN_READABLE); let opt_kb = options.get_flag(options::size::KIBIBYTES); - let bs_env_var = std::env::var_os("BLOCK_SIZE"); - let ls_bs_env_var = std::env::var_os("LS_BLOCK_SIZE"); - let pc_env_var = std::env::var_os("POSIXLY_CORRECT"); + let env_var_block_size = std::env::var_os("BLOCK_SIZE"); + let env_var_ls_block_size = std::env::var_os("LS_BLOCK_SIZE"); + let env_var_posixly_correct = std::env::var_os("POSIXLY_CORRECT"); let size_format = if opt_si { SizeFormat::Decimal @@ -768,13 +768,13 @@ impl Config { SizeFormat::Bytes }; - let raw_bs = if let Some(cmd_line_bs) = cmd_line_bs { - OsString::from(cmd_line_bs) + let raw_block_size = if let Some(opt_block_size) = opt_block_size { + OsString::from(opt_block_size) } else if !opt_kb { - if let Some(ls_bs_env_var) = ls_bs_env_var { - ls_bs_env_var - } else if let Some(bs_env_var) = bs_env_var { - bs_env_var + if let Some(env_var_ls_block_size) = env_var_ls_block_size { + env_var_ls_block_size + } else if let Some(env_var_block_size) = env_var_block_size { + env_var_block_size } else { OsString::from("") } @@ -782,15 +782,17 @@ impl Config { OsString::from("") }; - let block_size: Option = if !opt_si && !opt_hr && !raw_bs.is_empty() { - match parse_size_u64(&raw_bs.to_string_lossy()) { + let block_size: Option = if !opt_si && !opt_hr && !raw_block_size.is_empty() { + match parse_size_u64(&raw_block_size.to_string_lossy()) { Ok(size) => Some(size), Err(_) => { - show!(LsError::BlockSizeParseError(cmd_line_bs.unwrap().clone())); + show!(LsError::BlockSizeParseError( + opt_block_size.unwrap().clone() + )); None } } - } else if let Some(pc) = pc_env_var { + } 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 { From 51fc2d7564b29de22936e8ca4a73883aeca77662 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 1 Dec 2023 16:27:05 +0100 Subject: [PATCH 3/3] 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 3745cfc9df3..f645e31d3c2 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 19a3f5578fa..fcd57170d48 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"); +}