mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #7742 from BenWiederhake/dev-du-block-size-0
du: don't panic on block-size 0
This commit is contained in:
commit
689aaf9474
2 changed files with 27 additions and 5 deletions
|
@ -683,11 +683,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
} else if matches.get_flag(options::BLOCK_SIZE_1M) {
|
} else if matches.get_flag(options::BLOCK_SIZE_1M) {
|
||||||
SizeFormat::BlockSize(1024 * 1024)
|
SizeFormat::BlockSize(1024 * 1024)
|
||||||
} else {
|
} else {
|
||||||
SizeFormat::BlockSize(read_block_size(
|
let block_size_str = matches.get_one::<String>(options::BLOCK_SIZE);
|
||||||
matches
|
let block_size = read_block_size(block_size_str.map(AsRef::as_ref))?;
|
||||||
.get_one::<String>(options::BLOCK_SIZE)
|
if block_size == 0 {
|
||||||
.map(AsRef::as_ref),
|
return Err(std::io::Error::other(format!(
|
||||||
)?)
|
"invalid --{} argument {}",
|
||||||
|
options::BLOCK_SIZE,
|
||||||
|
block_size_str.map_or("???BUG", |v| v).quote()
|
||||||
|
))
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
SizeFormat::BlockSize(block_size)
|
||||||
};
|
};
|
||||||
|
|
||||||
let traversal_options = TraversalOptions {
|
let traversal_options = TraversalOptions {
|
||||||
|
|
|
@ -1248,3 +1248,19 @@ fn test_du_no_deduplicated_input_args() {
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(result_seq, ["2\td", "2\td", "2\td"]);
|
assert_eq!(result_seq, ["2\td", "2\td", "2\td"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_du_blocksize_zero_do_not_panic() {
|
||||||
|
let ts = TestScenario::new(util_name!());
|
||||||
|
let at = &ts.fixtures;
|
||||||
|
at.write("foo", "some content");
|
||||||
|
for block_size in ["0", "00", "000", "0x0"] {
|
||||||
|
ts.ucmd()
|
||||||
|
.arg(format!("-B{block_size}"))
|
||||||
|
.arg("foo")
|
||||||
|
.fails()
|
||||||
|
.stderr_only(format!(
|
||||||
|
"du: invalid --block-size argument '{block_size}'\n"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue