1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #5677 from cakebaker/ls_support_blocksize_env_var

ls: recognize BLOCKSIZE env var
This commit is contained in:
Sylvestre Ledru 2023-12-20 15:21:59 +01:00 committed by GitHub
commit de5c66adae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 8 deletions

View file

@ -810,10 +810,6 @@ impl Config {
|| options.get_flag(options::size::HUMAN_READABLE); || options.get_flag(options::size::HUMAN_READABLE);
let opt_kb = options.get_flag(options::size::KIBIBYTES); let opt_kb = options.get_flag(options::size::KIBIBYTES);
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 { let size_format = if opt_si {
SizeFormat::Decimal SizeFormat::Decimal
} else if opt_hr { } else if opt_hr {
@ -822,6 +818,11 @@ impl Config {
SizeFormat::Bytes SizeFormat::Bytes
}; };
let env_var_blocksize = std::env::var_os("BLOCKSIZE");
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 raw_block_size = if let Some(opt_block_size) = opt_block_size { let raw_block_size = if let Some(opt_block_size) = opt_block_size {
OsString::from(opt_block_size) OsString::from(opt_block_size)
} else if !opt_kb { } else if !opt_kb {
@ -829,6 +830,8 @@ impl Config {
env_var_ls_block_size env_var_ls_block_size
} else if let Some(env_var_block_size) = env_var_block_size { } else if let Some(env_var_block_size) = env_var_block_size {
env_var_block_size env_var_block_size
} else if let Some(env_var_blocksize) = env_var_blocksize {
env_var_blocksize
} else { } else {
OsString::from("") OsString::from("")
} }

View file

@ -3839,7 +3839,7 @@ fn test_ls_cf_output_should_be_delimited_by_tab() {
#[cfg(all(unix, feature = "dd"))] #[cfg(all(unix, feature = "dd"))]
#[test] #[test]
fn test_posixly_correct() { fn test_posixly_correct_and_block_size_env_vars() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
scene scene
@ -3852,16 +3852,42 @@ fn test_posixly_correct() {
scene scene
.ucmd() .ucmd()
.arg("-s") .arg("-l")
.succeeds() .succeeds()
.stdout_contains_line("total 4"); .stdout_contains_line("total 4")
.stdout_contains(" 1024 ");
scene scene
.ucmd() .ucmd()
.arg("-s") .arg("-l")
.env("POSIXLY_CORRECT", "some_value") .env("POSIXLY_CORRECT", "some_value")
.succeeds() .succeeds()
.stdout_contains_line("total 8"); .stdout_contains_line("total 8");
//.stdout_contains(" 1024 "); // TODO needs second internal blocksize
scene
.ucmd()
.arg("-l")
.env("LS_BLOCK_SIZE", "512")
.succeeds()
.stdout_contains_line("total 8")
.stdout_contains(" 2 ");
scene
.ucmd()
.arg("-l")
.env("BLOCK_SIZE", "512")
.succeeds()
.stdout_contains_line("total 8")
.stdout_contains(" 2 ");
scene
.ucmd()
.arg("-l")
.env("BLOCKSIZE", "512")
.succeeds()
.stdout_contains_line("total 8");
//.stdout_contains(" 1024 "); // TODO needs second internal blocksize
} }
#[test] #[test]
@ -3880,6 +3906,7 @@ fn test_ls_invalid_block_size() {
fn test_ls_invalid_block_size_in_env_var() { fn test_ls_invalid_block_size_in_env_var() {
new_ucmd!().env("LS_BLOCK_SIZE", "invalid").succeeds(); new_ucmd!().env("LS_BLOCK_SIZE", "invalid").succeeds();
new_ucmd!().env("BLOCK_SIZE", "invalid").succeeds(); new_ucmd!().env("BLOCK_SIZE", "invalid").succeeds();
new_ucmd!().env("BLOCKSIZE", "invalid").succeeds();
} }
#[cfg(all(unix, feature = "dd"))] #[cfg(all(unix, feature = "dd"))]