chown: warn when '.' is used as owner:group separator

When the spec contains '.' but no ':', emit a warning matching GNU
coreutils behavior and re-parse with '.' as separator so both owner
and group are applied.

Closes #11352
This commit is contained in:
Eyüp Can Akman
2026-03-31 10:29:24 +02:00
committed by Daniel Hofstetter
parent af81585b60
commit f6451c7d20
4 changed files with 84 additions and 8 deletions
+62 -1
View File
@@ -149,7 +149,8 @@ fn test_chown_only_owner_colon() {
.arg("--verbose")
.arg(file1)
.succeeds()
.stderr_contains("retained as");
.stderr_contains("retained as")
.stderr_contains("warning: '.' should be ':'");
scene
.ucmd()
@@ -160,6 +161,66 @@ fn test_chown_only_owner_colon() {
.stderr_contains("failed to change");
}
#[test]
fn test_chown_dot_separator_warning() {
// test that using '.' as separator emits a warning
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let result = scene.cmd("whoami").run();
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let file1 = "test_chown_dot_warn";
at.touch(file1);
let result = scene.cmd("id").arg("-gn").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
// chown user. file should warn about '.' separator
scene
.ucmd()
.arg(format!("{user_name}."))
.arg(file1)
.succeeds()
.stderr_contains("warning: '.' should be ':'");
// chown user.group file should warn AND apply both owner and group
let result = scene
.ucmd()
.arg(format!("{user_name}.{group_name}"))
.arg("--verbose")
.arg(file1)
.run();
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains("warning: '.' should be ':'");
// "retained as" on Linux, "changed ownership" on BSDs (group inherited from parent dir)
assert!(
result.stderr_str().contains("retained as")
|| result.stderr_str().contains("changed ownership"),
"expected verbose ownership output, got: {}",
result.stderr_str()
);
// chown user: file should not warn
scene
.ucmd()
.arg(format!("{user_name}:"))
.arg(file1)
.succeeds()
.stderr_does_not_contain("warning");
}
#[test]
fn test_chown_only_colon() {
// test chown : file.txt