diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 19c4eced2..c2b51ae5e 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -234,9 +234,12 @@ impl Chmoder { fn walk_dir(&self, file_path: &Path) -> UResult<()> { let mut r = self.chmod_file(file_path); - if file_path.is_dir() { - for dir_entry in fs::read_dir(file_path)? { - r = self.walk_dir(dir_entry?.path().as_path()); + if !is_symlink(file_path) && file_path.is_dir() { + for dir_entry in file_path.read_dir()? { + let path = dir_entry?.path(); + if !is_symlink(&path) { + r = self.walk_dir(path.as_path()); + } } } r diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 6cbe7e887..373ad97ce 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -473,8 +473,8 @@ fn test_chmod_symlink_non_existing_file_recursive() { let expected_stdout = &format!( // spell-checker:disable-next-line - "mode of '{}' retained as 0755 (rwxr-xr-x)\nneither symbolic link '{}/{}' nor referent has been changed", - test_directory, test_directory, test_symlink + "mode of '{}' retained as 0755 (rwxr-xr-x)", + test_directory ); // '-v': this should succeed without stderr