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

install: fix strip program stdout and destination hyphen handling #5718 (#5848)

* Fix missing dependency to "process" to make it compile.

* fix issue of not forwarding stdout from strip program

* fix issue of applying "./" redundantly

* cargo fmt
This commit is contained in:
Ulrich Hornung 2024-01-17 10:07:34 +01:00 committed by GitHub
parent 55b7b2fcb5
commit dc533a915a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 14 deletions

View file

@ -25,6 +25,7 @@ uucore = { workspace = true, features = [
"mode", "mode",
"perms", "perms",
"entries", "entries",
"process",
] } ] }
[[bin]] [[bin]]

View file

@ -776,27 +776,23 @@ fn copy_file(from: &Path, to: &Path) -> UResult<()> {
/// ///
fn strip_file(to: &Path, b: &Behavior) -> UResult<()> { fn strip_file(to: &Path, b: &Behavior) -> UResult<()> {
// Check if the filename starts with a hyphen and adjust the path // Check if the filename starts with a hyphen and adjust the path
let to = if to let to_str = to.as_os_str().to_str().unwrap_or_default();
.file_name() let to = if to_str.starts_with('-') {
.unwrap_or_default()
.to_str()
.unwrap_or_default()
.starts_with('-')
{
let mut new_path = PathBuf::from("."); let mut new_path = PathBuf::from(".");
new_path.push(to); new_path.push(to);
new_path new_path
} else { } else {
to.to_path_buf() to.to_path_buf()
}; };
match process::Command::new(&b.strip_program).arg(&to).output() { match process::Command::new(&b.strip_program).arg(&to).status() {
Ok(o) => { Ok(status) => {
if !o.status.success() { if !status.success() {
// Follow GNU's behavior: if strip fails, removes the target // Follow GNU's behavior: if strip fails, removes the target
let _ = fs::remove_file(to); let _ = fs::remove_file(to);
return Err(InstallError::StripProgramFailed( return Err(InstallError::StripProgramFailed(format!(
String::from_utf8(o.stderr).unwrap_or_default(), "strip process terminated abnormally - exit code: {}",
) status.code().unwrap()
))
.into()); .into());
} }
} }

View file

@ -699,7 +699,20 @@ fn test_install_and_strip_with_program_hyphen() {
.arg("src") .arg("src")
.arg("-dest") .arg("-dest")
.succeeds() .succeeds()
.no_stderr(); .no_stderr()
.stdout_is("./-dest\n");
scene
.ucmd()
.arg("-s")
.arg("--strip-program")
.arg("./no-hyphen")
.arg("--")
.arg("src")
.arg("./-dest")
.succeeds()
.no_stderr()
.stdout_is("./-dest\n");
} }
#[test] #[test]