Skip to content

Commit d627d76

Browse files
committed
install -C: also the manage the ignore case
1 parent bdcd2ef commit d627d76

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

src/uu/install/locales/en-US.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ install-error-missing-file-operand = missing file operand
4848
install-error-missing-destination-operand = missing destination file operand after '{ $path }'
4949
install-error-failed-to-remove = Failed to remove existing file { $path }. Error: { $error }
5050
51+
# Warning messages
52+
install-warning-compare-ignored = the --compare (-C) option is ignored when you specify a mode with non-permission bits
53+
5154
# Verbose output
5255
install-verbose-creating-directory = creating directory { $path }
5356
install-verbose-creating-directory-step = install: creating directory { $path }

src/uu/install/locales/fr-FR.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ install-error-missing-file-operand = opérande de fichier manquant
4848
install-error-missing-destination-operand = opérande de fichier de destination manquant après '{ $path }'
4949
install-error-failed-to-remove = Échec de la suppression du fichier existant { $path }. Erreur : { $error }
5050
51+
# Messages d'avertissement
52+
install-warning-compare-ignored = l'option --compare (-C) est ignorée quand un mode est indiqué avec des bits non liés à des droits
53+
5154
# Sortie détaillée
5255
install-verbose-creating-directory = création du répertoire { $path }
5356
install-verbose-creating-directory-step = install : création du répertoire { $path }

src/uu/install/src/install.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,15 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
365365
return Err(1.into());
366366
}
367367

368+
// Check if compare is used with non-permission mode bits
369+
if compare && specified_mode.is_some() {
370+
let mode = specified_mode.unwrap();
371+
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
372+
if mode & non_permission_bits != 0 {
373+
show_error!("{}", get_message("install-warning-compare-ignored"));
374+
}
375+
}
376+
368377
let owner = matches
369378
.get_one::<String>(OPT_OWNER)
370379
.map(|s| s.as_str())

tests/by-util/test_install.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,3 +2278,50 @@ fn test_selinux_invalid_args() {
22782278
at.remove(&at.plus_as_string(dest));
22792279
}
22802280
}
2281+
2282+
#[test]
2283+
fn test_install_compare_with_mode_bits() {
2284+
let test_cases = [
2285+
("4755", "setuid bit", true),
2286+
("2755", "setgid bit", true),
2287+
("1755", "sticky bit", true),
2288+
("7755", "setuid + setgid + sticky bits", true),
2289+
("755", "permission-only mode", false),
2290+
];
2291+
2292+
for (mode, description, should_warn) in test_cases {
2293+
let scene = TestScenario::new(util_name!());
2294+
let at = &scene.fixtures;
2295+
let source = format!("source_file_{}", mode);
2296+
let dest = format!("dest_file_{}", mode);
2297+
2298+
at.write(&source, "test content");
2299+
2300+
let mode_arg = format!("--mode={}", mode);
2301+
2302+
if should_warn {
2303+
scene.ucmd().args(&["-C", &mode_arg, &source, &dest])
2304+
.succeeds()
2305+
.stderr_contains("the --compare (-C) option is ignored when you specify a mode with non-permission bits");
2306+
} else {
2307+
scene
2308+
.ucmd()
2309+
.args(&["-C", &mode_arg, &source, &dest])
2310+
.succeeds()
2311+
.no_stderr();
2312+
2313+
// Test second install should be no-op due to -C
2314+
scene
2315+
.ucmd()
2316+
.args(&["-C", &mode_arg, &source, &dest])
2317+
.succeeds()
2318+
.no_stderr();
2319+
}
2320+
2321+
assert!(
2322+
at.file_exists(&dest),
2323+
"Failed to create dest file for {}",
2324+
description
2325+
);
2326+
}
2327+
}

0 commit comments

Comments
 (0)