Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uu/install/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install-error-chmod-failed-detailed = { $path }: chmod failed with error { $erro
install-error-chown-failed = failed to chown { $path }: { $error }
install-error-invalid-target = invalid target { $path }: No such file or directory
install-error-target-not-dir = target { $path } is not a directory
install-error-backup-failed = cannot backup { $from } to { $to }
install-error-backup-failed = cannot backup { $from }: { $error }
install-error-install-failed = cannot install { $from } to { $to }: { $error }
install-error-strip-failed = strip program failed: { $error }
install-error-strip-abnormal = strip process terminated abnormally - exit code: { $code }
Expand Down
2 changes: 1 addition & 1 deletion src/uu/install/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install-error-chmod-failed-detailed = { $path } : échec du chmod avec l'erreur
install-error-chown-failed = échec du chown { $path } : { $error }
install-error-invalid-target = cible invalide { $path } : Aucun fichier ou répertoire de ce type
install-error-target-not-dir = la cible { $path } n'est pas un répertoire
install-error-backup-failed = impossible de sauvegarder { $from } vers { $to }
install-error-backup-failed = impossible de sauvegarder { $from } : { $error }
install-error-install-failed = impossible d'installer { $from } vers { $to }: { $error }
install-error-strip-failed = échec du programme strip : { $error }
install-error-strip-abnormal = le processus strip s'est terminé anormalement - code de sortie : { $code }
Expand Down
11 changes: 5 additions & 6 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use uucore::backup_control::{self, BackupMode};
use uucore::buf_copy::copy_fast;
use uucore::display::Quotable;
use uucore::entries::{grp2gid, usr2uid};
use uucore::error::{FromIo, UError, UResult, UUsageError};
use uucore::error::{FromIo, UError, UResult, UUsageError, strip_errno};
use uucore::fs::dir_strip_dot_for_creation;
use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown};
use uucore::process::{getegid, geteuid};
Expand Down Expand Up @@ -88,8 +88,8 @@ enum InstallError {
#[error("{}", translate!("install-error-target-not-dir", "path" => .0.quote()))]
TargetDirIsntDir(PathBuf),

#[error("{}", translate!("install-error-backup-failed", "from" => .0.quote(), "to" => .1.quote()))]
BackupFailed(PathBuf, PathBuf, #[source] std::io::Error),
#[error("{}", translate!("install-error-backup-failed", "from" => .0.quote(), "error" => strip_errno(.1)))]
BackupFailed(PathBuf, #[source] std::io::Error),

#[error("{}", translate!("install-error-install-failed", "from" => .0.quote(), "to" => .1.quote(), "error" => .2.clone()))]
InstallFailed(PathBuf, PathBuf, String),
Expand Down Expand Up @@ -916,9 +916,8 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult<Option<PathBuf>> {
}
let backup_path = backup_control::get_backup_path(b.backup_mode, to, &b.suffix);
if let Some(ref backup_path) = backup_path {
fs::rename(to, backup_path).map_err(|err| {
InstallError::BackupFailed(to.to_path_buf(), backup_path.clone(), err)
})?;
fs::rename(to, backup_path)
.map_err(|err| InstallError::BackupFailed(to.to_path_buf(), err))?;
}
Ok(backup_path)
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::process;
use std::sync::OnceLock;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::thread::sleep;
use uucore::error::strip_errno;
use uucore::process::{getegid, geteuid};
#[cfg(all(
feature = "feat_selinux",
Expand Down Expand Up @@ -1383,6 +1384,20 @@ fn test_install_backup_custom_suffix_via_env() {
assert!(at.file_exists(format!("{file_b}{suffix}")));
}

#[test]
fn test_install_backup_error_includes_cause() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("source");
at.touch("target");
at.mkdir("target.backup");
let error = strip_errno(&fs::rename(at.plus("target"), at.plus("target.backup")).unwrap_err());

ucmd.env("SIMPLE_BACKUP_SUFFIX", ".backup")
.args(&["--backup", "source", "target"])
.fails()
.stderr_is(format!("install: cannot backup 'target': {error}\n"));
}

#[test]
fn test_install_backup_numbered_with_t() {
let scene = TestScenario::new(util_name!());
Expand Down
Loading