Skip to content

Commit 85a7812

Browse files
authored
Merge pull request #8928 from yrakcaz/main
ls: fix zero block size handling to match GNU ls
2 parents db9c50c + 3ff51d6 commit 85a7812

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/uu/ls/src/ls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use uucore::{
6868
line_ending::LineEnding,
6969
os_str_as_bytes_lossy,
7070
parser::parse_glob,
71-
parser::parse_size::parse_size_u64,
71+
parser::parse_size::parse_size_non_zero_u64,
7272
parser::shortcut_value_parser::ShortcutValueParser,
7373
quoting_style::{QuotingStyle, locale_aware_escape_dir_name, locale_aware_escape_name},
7474
show, show_error, show_warning,
@@ -902,7 +902,7 @@ impl Config {
902902

903903
let (file_size_block_size, block_size) = if !opt_si && !opt_hr && !raw_block_size.is_empty()
904904
{
905-
match parse_size_u64(&raw_block_size.to_string_lossy()) {
905+
match parse_size_non_zero_u64(&raw_block_size.to_string_lossy()) {
906906
Ok(size) => match (is_env_var_blocksize, opt_kb) {
907907
(true, true) => (DEFAULT_FILE_SIZE_BLOCK_SIZE, DEFAULT_BLOCK_SIZE),
908908
(true, false) => (DEFAULT_FILE_SIZE_BLOCK_SIZE, size),

tests/by-util/test_ls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,6 +5355,12 @@ fn test_ls_invalid_block_size() {
53555355
.fails_with_code(2)
53565356
.no_stdout()
53575357
.stderr_is("ls: invalid --block-size argument 'invalid'\n");
5358+
5359+
new_ucmd!()
5360+
.arg("--block-size=0")
5361+
.fails_with_code(2)
5362+
.no_stdout()
5363+
.stderr_is("ls: invalid --block-size argument '0'\n");
53585364
}
53595365

53605366
#[cfg(all(unix, feature = "dd"))]
@@ -5394,6 +5400,14 @@ fn test_ls_invalid_block_size_in_env_var() {
53945400
.succeeds()
53955401
.stdout_contains_line("total 4")
53965402
.stdout_contains(" 1024 ");
5403+
5404+
scene
5405+
.ucmd()
5406+
.arg("-og")
5407+
.env("BLOCKSIZE", "0")
5408+
.succeeds()
5409+
.stdout_contains_line("total 4")
5410+
.stdout_contains(" 1024 ");
53975411
}
53985412

53995413
#[cfg(all(unix, feature = "dd"))]

0 commit comments

Comments
 (0)