mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
ls: set correct block size when -k is provided
This commit is contained in:
parent
12ade87786
commit
270ac90cc1
2 changed files with 74 additions and 18 deletions
|
@ -828,8 +828,7 @@ impl Config {
|
||||||
|
|
||||||
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 let Some(env_var_ls_block_size) = env_var_ls_block_size {
|
||||||
if let Some(env_var_ls_block_size) = 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 {
|
} else if let Some(env_var_block_size) = env_var_block_size {
|
||||||
env_var_block_size
|
env_var_block_size
|
||||||
|
@ -838,21 +837,24 @@ impl Config {
|
||||||
env_var_blocksize
|
env_var_blocksize
|
||||||
} else {
|
} else {
|
||||||
OsString::from("")
|
OsString::from("")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
OsString::from("")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (file_size_block_size, block_size) = if !opt_si && !opt_hr && !raw_block_size.is_empty()
|
let (file_size_block_size, block_size) = if !opt_si && !opt_hr && !raw_block_size.is_empty()
|
||||||
{
|
{
|
||||||
match parse_size_u64(&raw_block_size.to_string_lossy()) {
|
match parse_size_u64(&raw_block_size.to_string_lossy()) {
|
||||||
Ok(size) => {
|
Ok(size) => match (is_env_var_blocksize, opt_kb) {
|
||||||
if is_env_var_blocksize {
|
(true, true) => (DEFAULT_FILE_SIZE_BLOCK_SIZE, DEFAULT_BLOCK_SIZE),
|
||||||
(DEFAULT_FILE_SIZE_BLOCK_SIZE, size)
|
(true, false) => (DEFAULT_FILE_SIZE_BLOCK_SIZE, size),
|
||||||
} else {
|
(false, true) => {
|
||||||
|
// --block-size overrides -k
|
||||||
|
if opt_block_size.is_some() {
|
||||||
(size, size)
|
(size, size)
|
||||||
|
} else {
|
||||||
|
(size, DEFAULT_BLOCK_SIZE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(false, false) => (size, size),
|
||||||
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// only fail if invalid block size was specified with --block-size,
|
// only fail if invalid block size was specified with --block-size,
|
||||||
// ignore invalid block size from env vars
|
// ignore invalid block size from env vars
|
||||||
|
@ -869,7 +871,11 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if env_var_posixly_correct.is_some() {
|
} else if env_var_posixly_correct.is_some() {
|
||||||
|
if opt_kb {
|
||||||
|
(DEFAULT_FILE_SIZE_BLOCK_SIZE, DEFAULT_BLOCK_SIZE)
|
||||||
|
} else {
|
||||||
(DEFAULT_FILE_SIZE_BLOCK_SIZE, POSIXLY_CORRECT_BLOCK_SIZE)
|
(DEFAULT_FILE_SIZE_BLOCK_SIZE, POSIXLY_CORRECT_BLOCK_SIZE)
|
||||||
|
}
|
||||||
} else if opt_si {
|
} else if opt_si {
|
||||||
(DEFAULT_FILE_SIZE_BLOCK_SIZE, 1000)
|
(DEFAULT_FILE_SIZE_BLOCK_SIZE, 1000)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3890,6 +3890,56 @@ fn test_posixly_correct_and_block_size_env_vars() {
|
||||||
.stdout_contains(" 1024 ");
|
.stdout_contains(" 1024 ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "dd"))]
|
||||||
|
#[test]
|
||||||
|
fn test_posixly_correct_and_block_size_env_vars_with_k() {
|
||||||
|
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("-l")
|
||||||
|
.arg("-k")
|
||||||
|
.env("POSIXLY_CORRECT", "some_value")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains_line("total 4")
|
||||||
|
.stdout_contains(" 1024 ");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-l")
|
||||||
|
.arg("-k")
|
||||||
|
.env("LS_BLOCK_SIZE", "512")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains_line("total 4")
|
||||||
|
.stdout_contains(" 2 ");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-l")
|
||||||
|
.arg("-k")
|
||||||
|
.env("BLOCK_SIZE", "512")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains_line("total 4")
|
||||||
|
.stdout_contains(" 2 ");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-l")
|
||||||
|
.arg("-k")
|
||||||
|
.env("BLOCKSIZE", "512")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains_line("total 4")
|
||||||
|
.stdout_contains(" 1024 ");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_invalid_block_size() {
|
fn test_ls_invalid_block_size() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue