mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #6854 from sylvestre/fmt
fmt: generate an error if the input is a directory
This commit is contained in:
commit
19a19f004f
2 changed files with 12 additions and 0 deletions
|
@ -189,6 +189,13 @@ fn process_file(
|
||||||
_ => {
|
_ => {
|
||||||
let f = File::open(file_name)
|
let f = File::open(file_name)
|
||||||
.map_err_context(|| format!("cannot open {} for reading", file_name.quote()))?;
|
.map_err_context(|| format!("cannot open {} for reading", file_name.quote()))?;
|
||||||
|
if f.metadata()
|
||||||
|
.map_err_context(|| format!("cannot get metadata for {}", file_name.quote()))?
|
||||||
|
.is_dir()
|
||||||
|
{
|
||||||
|
return Err(USimpleError::new(1, "read error".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
Box::new(f) as Box<dyn Read + 'static>
|
Box::new(f) as Box<dyn Read + 'static>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,11 @@ fn test_invalid_arg() {
|
||||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_input() {
|
||||||
|
new_ucmd!().arg(".").fails().code_is(1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fmt() {
|
fn test_fmt() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue