mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
install: When install --strip-program=foor fails, remove the target file
Should fix: tests/install/strip-program.sh
This commit is contained in:
parent
62d96db16b
commit
6da73e6a6d
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() {
|
match process::Command::new(&b.strip_program).arg(to).output() {
|
||||||
Ok(o) => {
|
Ok(o) => {
|
||||||
if !o.status.success() {
|
if !o.status.success() {
|
||||||
|
// Follow GNU's behavior: if strip fails, removes the target
|
||||||
|
let _ = fs::remove_file(to);
|
||||||
return Err(InstallError::StripProgramFailed(
|
return Err(InstallError::StripProgramFailed(
|
||||||
String::from_utf8(o.stderr).unwrap_or_default(),
|
String::from_utf8(o.stderr).unwrap_or_default(),
|
||||||
)
|
)
|
||||||
.into());
|
.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]
|
#[test]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn test_install_and_strip_with_invalid_program() {
|
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("-s")
|
||||||
.arg("--strip-program")
|
.arg("--strip-program")
|
||||||
.arg("/bin/date")
|
.arg("/bin/date")
|
||||||
|
@ -615,12 +619,17 @@ fn test_install_and_strip_with_invalid_program() {
|
||||||
.arg(STRIP_TARGET_FILE)
|
.arg(STRIP_TARGET_FILE)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("strip program failed");
|
.stderr_contains("strip program failed");
|
||||||
|
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn test_install_and_strip_with_non_existent_program() {
|
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("-s")
|
||||||
.arg("--strip-program")
|
.arg("--strip-program")
|
||||||
.arg("/usr/bin/non_existent_program")
|
.arg("/usr/bin/non_existent_program")
|
||||||
|
@ -628,6 +637,7 @@ fn test_install_and_strip_with_non_existent_program() {
|
||||||
.arg(STRIP_TARGET_FILE)
|
.arg(STRIP_TARGET_FILE)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("No such file or directory");
|
.stderr_contains("No such file or directory");
|
||||||
|
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue