mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #7090 from sylvestre/env
env/stbuf: better handling of the errors
This commit is contained in:
commit
c531fb3973
4 changed files with 60 additions and 13 deletions
23
src/uu/env/src/env.rs
vendored
23
src/uu/env/src/env.rs
vendored
|
@ -539,16 +539,19 @@ impl EnvAppData {
|
||||||
}
|
}
|
||||||
return Err(exit.code().unwrap().into());
|
return Err(exit.code().unwrap().into());
|
||||||
}
|
}
|
||||||
Err(ref err)
|
Err(ref err) => match err.kind() {
|
||||||
if (err.kind() == io::ErrorKind::NotFound)
|
io::ErrorKind::NotFound | io::ErrorKind::InvalidInput => {
|
||||||
|| (err.kind() == io::ErrorKind::InvalidInput) =>
|
return Err(self.make_error_no_such_file_or_dir(prog.deref()));
|
||||||
{
|
}
|
||||||
return Err(self.make_error_no_such_file_or_dir(prog.deref()));
|
io::ErrorKind::PermissionDenied => {
|
||||||
}
|
uucore::show_error!("{}: Permission denied", prog.quote());
|
||||||
Err(e) => {
|
return Err(126.into());
|
||||||
uucore::show_error!("unknown error: {:?}", e);
|
}
|
||||||
return Err(126.into());
|
_ => {
|
||||||
}
|
uucore::show_error!("unknown error: {:?}", err);
|
||||||
|
return Err(126.into());
|
||||||
|
}
|
||||||
|
},
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -157,9 +157,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
set_command_env(&mut command, "_STDBUF_E", &options.stderr);
|
set_command_env(&mut command, "_STDBUF_E", &options.stderr);
|
||||||
command.args(command_params);
|
command.args(command_params);
|
||||||
|
|
||||||
let mut process = command
|
const EXEC_ERROR: &str = "failed to execute process:";
|
||||||
.spawn()
|
let mut process = match command.spawn() {
|
||||||
.map_err_context(|| "failed to execute process".to_string())?;
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
return match e.kind() {
|
||||||
|
std::io::ErrorKind::PermissionDenied => Err(USimpleError::new(
|
||||||
|
126,
|
||||||
|
format!("{EXEC_ERROR} Permission denied"),
|
||||||
|
)),
|
||||||
|
std::io::ErrorKind::NotFound => Err(USimpleError::new(
|
||||||
|
127,
|
||||||
|
format!("{EXEC_ERROR} No such file or directory"),
|
||||||
|
)),
|
||||||
|
_ => Err(USimpleError::new(1, format!("{EXEC_ERROR} {}", e))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let status = process.wait().map_err_context(String::new)?;
|
let status = process.wait().map_err_context(String::new)?;
|
||||||
match status.code() {
|
match status.code() {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
|
|
|
@ -80,6 +80,15 @@ fn test_env_version() {
|
||||||
.stdout_contains(util_name!());
|
.stdout_contains(util_name!());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_env_permissions() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg(".")
|
||||||
|
.fails()
|
||||||
|
.code_is(126)
|
||||||
|
.stderr_is("env: '.': Permission denied\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_echo() {
|
fn test_echo() {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|
|
@ -10,6 +10,26 @@ fn invalid_input() {
|
||||||
new_ucmd!().arg("-/").fails().code_is(125);
|
new_ucmd!().arg("-/").fails().code_is(125);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_permission() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-o1")
|
||||||
|
.arg(".")
|
||||||
|
.fails()
|
||||||
|
.code_is(126)
|
||||||
|
.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")))]
|
#[cfg(all(not(target_os = "windows"), not(target_os = "openbsd")))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stdbuf_unbuffered_stdout() {
|
fn test_stdbuf_unbuffered_stdout() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue