mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
Merge pull request #3419 from sylvestre/install-strip
install: When install --strip-program=foor fails, remove the target file
This commit is contained in:
commit
ee50f408bd
2 changed files with 19 additions and 3 deletions
|
@ -594,13 +594,19 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
|
|||
match process::Command::new(&b.strip_program).arg(to).output() {
|
||||
Ok(o) => {
|
||||
if !o.status.success() {
|
||||
// Follow GNU's behavior: if strip fails, removes the target
|
||||
let _ = fs::remove_file(to);
|
||||
return Err(InstallError::StripProgramFailed(
|
||||
String::from_utf8(o.stderr).unwrap_or_default(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(InstallError::StripProgramFailed(e.to_string()).into()),
|
||||
Err(e) => {
|
||||
// Follow GNU's behavior: if strip fails, removes the target
|
||||
let _ = fs::remove_file(to);
|
||||
return Err(InstallError::StripProgramFailed(e.to_string()).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -607,7 +607,11 @@ fn test_install_and_strip_with_program() {
|
|||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_install_and_strip_with_invalid_program() {
|
||||
new_ucmd!()
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-s")
|
||||
.arg("--strip-program")
|
||||
.arg("/bin/date")
|
||||
|
@ -615,12 +619,17 @@ fn test_install_and_strip_with_invalid_program() {
|
|||
.arg(STRIP_TARGET_FILE)
|
||||
.fails()
|
||||
.stderr_contains("strip program failed");
|
||||
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_install_and_strip_with_non_existent_program() {
|
||||
new_ucmd!()
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-s")
|
||||
.arg("--strip-program")
|
||||
.arg("/usr/bin/non_existent_program")
|
||||
|
@ -628,6 +637,7 @@ fn test_install_and_strip_with_non_existent_program() {
|
|||
.arg(STRIP_TARGET_FILE)
|
||||
.fails()
|
||||
.stderr_contains("No such file or directory");
|
||||
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue