1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

install -C: also the manage the ignore case

This commit is contained in:
Sylvestre Ledru 2025-06-28 11:51:00 +02:00
parent bdcd2ef00a
commit d9c72dcdc8
4 changed files with 98 additions and 9 deletions

View file

@ -48,6 +48,9 @@ install-error-missing-file-operand = missing file operand
install-error-missing-destination-operand = missing destination file operand after '{ $path }' install-error-missing-destination-operand = missing destination file operand after '{ $path }'
install-error-failed-to-remove = Failed to remove existing file { $path }. Error: { $error } install-error-failed-to-remove = Failed to remove existing file { $path }. Error: { $error }
# Warning messages
install-warning-compare-ignored = the --compare (-C) option is ignored when you specify a mode with non-permission bits
# Verbose output # Verbose output
install-verbose-creating-directory = creating directory { $path } install-verbose-creating-directory = creating directory { $path }
install-verbose-creating-directory-step = install: creating directory { $path } install-verbose-creating-directory-step = install: creating directory { $path }

View file

@ -48,6 +48,9 @@ install-error-missing-file-operand = opérande de fichier manquant
install-error-missing-destination-operand = opérande de fichier de destination manquant après '{ $path }' install-error-missing-destination-operand = opérande de fichier de destination manquant après '{ $path }'
install-error-failed-to-remove = Échec de la suppression du fichier existant { $path }. Erreur : { $error } install-error-failed-to-remove = Échec de la suppression du fichier existant { $path }. Erreur : { $error }
# Messages d'avertissement
install-warning-compare-ignored = l'option --compare (-C) est ignorée quand un mode est indiqué avec des bits non liés à des droits
# Sortie détaillée # Sortie détaillée
install-verbose-creating-directory = création du répertoire { $path } install-verbose-creating-directory = création du répertoire { $path }
install-verbose-creating-directory-step = install : création du répertoire { $path } install-verbose-creating-directory-step = install : création du répertoire { $path }

View file

@ -365,6 +365,15 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
return Err(1.into()); return Err(1.into());
} }
// Check if compare is used with non-permission mode bits
if compare && specified_mode.is_some() {
let mode = specified_mode.unwrap();
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
if mode & non_permission_bits != 0 {
show_error!("{}", get_message("install-warning-compare-ignored"));
}
}
let owner = matches let owner = matches
.get_one::<String>(OPT_OWNER) .get_one::<String>(OPT_OWNER)
.map(|s| s.as_str()) .map(|s| s.as_str())

View file

@ -643,7 +643,9 @@ fn test_install_copy_then_compare_file_with_extra_mode() {
.arg("-m") .arg("-m")
.arg("1644") .arg("1644")
.succeeds() .succeeds()
.no_stderr(); .stderr_contains(
"the --compare (-C) option is ignored when you specify a mode with non-permission bits",
);
file2_meta = at.metadata(file2); file2_meta = at.metadata(file2);
let after_install_sticky = FileTime::from_last_modification_time(&file2_meta); let after_install_sticky = FileTime::from_last_modification_time(&file2_meta);
@ -2222,20 +2224,37 @@ fn test_selinux() {
let args = ["-Z", "--context=unconfined_u:object_r:user_tmp_t:s0"]; let args = ["-Z", "--context=unconfined_u:object_r:user_tmp_t:s0"];
for arg in args { for arg in args {
new_ucmd!() let result = new_ucmd!()
.arg(arg) .arg(arg)
.arg("-v") .arg("-v")
.arg(at.plus_as_string(src)) .arg(at.plus_as_string(src))
.arg(at.plus_as_string(dest)) .arg(at.plus_as_string(dest))
.succeeds() .run();
.stdout_contains("orig' -> '");
// Skip test if SELinux is not enabled
if result
.stderr_str()
.contains("SELinux is not enabled on this system")
{
println!("Skipping SELinux test: SELinux is not enabled");
at.remove(&at.plus_as_string(dest));
continue;
}
result.success().stdout_contains("orig' -> '");
let getfattr_output = Command::new("getfattr") let getfattr_output = Command::new("getfattr")
.arg(at.plus_as_string(dest)) .arg(at.plus_as_string(dest))
.arg("-n") .arg("-n")
.arg("security.selinux") .arg("security.selinux")
.output() .output();
.expect("Failed to run `getfattr` on the destination file");
// Skip test if getfattr is not available
let Ok(getfattr_output) = getfattr_output else {
println!("Skipping SELinux test: getfattr not available");
at.remove(&at.plus_as_string(dest));
continue;
};
println!("{:?}", getfattr_output); println!("{:?}", getfattr_output);
assert!( assert!(
getfattr_output.status.success(), getfattr_output.status.success(),
@ -2267,14 +2286,69 @@ fn test_selinux_invalid_args() {
"--context=nconfined_u:object_r:user_tmp_t:s0", "--context=nconfined_u:object_r:user_tmp_t:s0",
]; ];
for arg in args { for arg in args {
new_ucmd!() let result = new_ucmd!()
.arg(arg) .arg(arg)
.arg("-v") .arg("-v")
.arg(at.plus_as_string(src)) .arg(at.plus_as_string(src))
.arg(at.plus_as_string(dest)) .arg(at.plus_as_string(dest))
.fails() .fails();
.stderr_contains("failed to set default file creation");
let stderr = result.stderr_str();
assert!(
stderr.contains("failed to set default file creation")
|| stderr.contains("SELinux is not enabled on this system"),
"Expected stderr to contain either 'failed to set default file creation' or 'SELinux is not enabled on this system', but got: '{}'",
stderr
);
at.remove(&at.plus_as_string(dest)); at.remove(&at.plus_as_string(dest));
} }
} }
#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "freebsd")))]
fn test_install_compare_with_mode_bits() {
let test_cases = [
("4755", "setuid bit", true),
("2755", "setgid bit", true),
("1755", "sticky bit", true),
("7755", "setuid + setgid + sticky bits", true),
("755", "permission-only mode", false),
];
for (mode, description, should_warn) in test_cases {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let source = format!("source_file_{}", mode);
let dest = format!("dest_file_{}", mode);
at.write(&source, "test content");
let mode_arg = format!("--mode={}", mode);
if should_warn {
scene.ucmd().args(&["-C", &mode_arg, &source, &dest])
.succeeds()
.stderr_contains("the --compare (-C) option is ignored when you specify a mode with non-permission bits");
} else {
scene
.ucmd()
.args(&["-C", &mode_arg, &source, &dest])
.succeeds()
.no_stderr();
// Test second install should be no-op due to -C
scene
.ucmd()
.args(&["-C", &mode_arg, &source, &dest])
.succeeds()
.no_stderr();
}
assert!(
at.file_exists(&dest),
"Failed to create dest file for {}",
description
);
}
}