mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
bug(chmod): chmod on symlink pointing to non existing file is failing (#1694)
This commit is contained in:
parent
88911be6e0
commit
013bb285cd
2 changed files with 46 additions and 1 deletions
|
@ -182,7 +182,17 @@ impl Chmoder {
|
||||||
Ok(meta) => meta.mode() & 0o7777,
|
Ok(meta) => meta.mode() & 0o7777,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if !self.quiet {
|
if !self.quiet {
|
||||||
show_error!("{}", err);
|
if is_symlink(file) {
|
||||||
|
if self.verbose {
|
||||||
|
show_info!(
|
||||||
|
"neither symbolic link '{}' nor referent has been changed",
|
||||||
|
file.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
|
show_error!("{}: '{}'", err, file.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Err(1);
|
return Err(1);
|
||||||
}
|
}
|
||||||
|
@ -260,3 +270,10 @@ impl Chmoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_symlink<P: AsRef<Path>>(path: P) -> bool {
|
||||||
|
match fs::symlink_metadata(path) {
|
||||||
|
Ok(m) => m.file_type().is_symlink(),
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -346,3 +346,31 @@ fn test_chmod_preserve_root() {
|
||||||
.stderr
|
.stderr
|
||||||
.contains("chmod: error: it is dangerous to operate recursively on '/'"));
|
.contains("chmod: error: it is dangerous to operate recursively on '/'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chmod_symlink_non_existing_file() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.symlink_file("/non-existing", "test-long.link");
|
||||||
|
|
||||||
|
let result = ucmd
|
||||||
|
.arg("-R")
|
||||||
|
.arg("755")
|
||||||
|
.arg("-v")
|
||||||
|
.arg("test-long.link")
|
||||||
|
.fails();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chmod_symlink_non_existing_recursive() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.mkdir("tmp");
|
||||||
|
at.symlink_file("/non-existing", "tmp/test-long.link");
|
||||||
|
|
||||||
|
let result = ucmd.arg("-R").arg("755").arg("-v").arg("tmp").succeeds();
|
||||||
|
// it should be a success
|
||||||
|
println!("stderr {}", result.stderr);
|
||||||
|
println!("stdout {}", result.stdout);
|
||||||
|
assert!(result
|
||||||
|
.stderr
|
||||||
|
.contains("neither symbolic link 'tmp/test-long.link' nor referent has been changed"));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue