1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

stdbuf: better handling when non existing files

Should fix tests/misc/stdbuf
This commit is contained in:
Sylvestre Ledru 2025-01-08 00:11:34 +01:00
parent 79645d45ce
commit 04d4c9e1ef
2 changed files with 30 additions and 12 deletions

View file

@ -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 => {
Err(e) => match e.kind() {
std::io::ErrorKind::PermissionDenied => {
return Err(USimpleError::new(
126,
"failed to execute process: Permission denied",
));
}
Err(e) => {
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)?;

View file

@ -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() {