mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
stdbuf: better handling when non existing files
Should fix tests/misc/stdbuf
This commit is contained in:
parent
79645d45ce
commit
04d4c9e1ef
2 changed files with 30 additions and 12 deletions
|
@ -159,18 +159,26 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
let mut process = match command.spawn() {
|
||||
Ok(process) => process,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {
|
||||
return Err(USimpleError::new(
|
||||
126,
|
||||
"failed to execute process: Permission denied",
|
||||
));
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format!("failed to execute process: {}", e),
|
||||
));
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::PermissionDenied => {
|
||||
return Err(USimpleError::new(
|
||||
126,
|
||||
"failed to execute process: Permission denied",
|
||||
));
|
||||
}
|
||||
std::io::ErrorKind::NotFound => {
|
||||
return Err(USimpleError::new(
|
||||
127,
|
||||
"failed to execute process: No such file or directory",
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format!("failed to execute process: {}", e),
|
||||
));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let status = process.wait().map_err_context(String::new)?;
|
||||
|
|
|
@ -20,6 +20,16 @@ fn test_permission() {
|
|||
.stderr_contains("Permission denied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_such() {
|
||||
new_ucmd!()
|
||||
.arg("-o1")
|
||||
.arg("no_such")
|
||||
.fails()
|
||||
.code_is(127)
|
||||
.stderr_contains("No such file or directory");
|
||||
}
|
||||
|
||||
#[cfg(all(not(target_os = "windows"), not(target_os = "openbsd")))]
|
||||
#[test]
|
||||
fn test_stdbuf_unbuffered_stdout() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue