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

chmod: ignore symbolic links during recursive directory traversal

This commit is contained in:
xxyzz 2022-03-06 09:38:39 +08:00
parent 3272a590db
commit ce385be575
No known key found for this signature in database
GPG key ID: F796163E6DCFEE9D
2 changed files with 8 additions and 5 deletions

View file

@ -234,9 +234,12 @@ impl Chmoder {
fn walk_dir(&self, file_path: &Path) -> UResult<()> { fn walk_dir(&self, file_path: &Path) -> UResult<()> {
let mut r = self.chmod_file(file_path); let mut r = self.chmod_file(file_path);
if file_path.is_dir() { if !is_symlink(file_path) && file_path.is_dir() {
for dir_entry in fs::read_dir(file_path)? { for dir_entry in file_path.read_dir()? {
r = self.walk_dir(dir_entry?.path().as_path()); let path = dir_entry?.path();
if !is_symlink(&path) {
r = self.walk_dir(path.as_path());
}
} }
} }
r r

View file

@ -473,8 +473,8 @@ fn test_chmod_symlink_non_existing_file_recursive() {
let expected_stdout = &format!( let expected_stdout = &format!(
// spell-checker:disable-next-line // spell-checker:disable-next-line
"mode of '{}' retained as 0755 (rwxr-xr-x)\nneither symbolic link '{}/{}' nor referent has been changed", "mode of '{}' retained as 0755 (rwxr-xr-x)",
test_directory, test_directory, test_symlink test_directory
); );
// '-v': this should succeed without stderr // '-v': this should succeed without stderr