Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/uu/rm/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Opt
let entry_stat = match dir_fd.stat_at(&entry_name, false) {
Ok(stat) => stat,
Err(e) => {
error = handle_error_with_force(e, &entry_path, options);
error |= handle_error_with_force(e, &entry_path, options);
continue;
}
};
Expand All @@ -395,21 +395,21 @@ pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Opt
// If we can't open the subdirectory for safe traversal,
// try to handle it as best we can with safe operations
if e.kind() == std::io::ErrorKind::PermissionDenied {
error = handle_permission_denied(
error |= handle_permission_denied(
dir_fd,
entry_name.as_ref(),
&entry_path,
options,
);
} else {
error = handle_error_with_force(e, &entry_path, options);
error |= handle_error_with_force(e, &entry_path, options);
}
continue;
}
};

let child_error = safe_remove_dir_recursive_impl(&entry_path, &child_dir_fd, options);
error = error || child_error;
error |= child_error;

// Ask user permission if needed for this subdirectory
if !child_error
Expand All @@ -421,12 +421,12 @@ pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Opt

// Remove the now-empty subdirectory using safe unlinkat
if !child_error {
error = handle_unlink(dir_fd, entry_name.as_ref(), &entry_path, true, options);
error |= handle_unlink(dir_fd, entry_name.as_ref(), &entry_path, true, options);
}
} else {
// Remove file - check if user wants to remove it first
if prompt_file_with_stat(&entry_path, &entry_stat, options) {
error = handle_unlink(dir_fd, entry_name.as_ref(), &entry_path, false, options);
error |= handle_unlink(dir_fd, entry_name.as_ref(), &entry_path, false, options);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/by-util/test_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,9 +1140,10 @@ fn test_rm_directory_not_writable() {

// Check for expected error message
// When the parent directory (b/a) doesn't have write permission,
// we get "Permission denied" when trying to remove the subdirectory
let stderr = result.stderr_str();
assert!(stderr.contains("rm: cannot remove 'b/a/p': Permission denied"));
// we get "Permission denied" when trying to remove the subdirectory.
// The error tracking must be correct so we don't attempt to remove the parent
// directory after child failure (which would produce extra "Directory not empty" errors).
result.stderr_only("rm: cannot remove 'b/a/p': Permission denied\n");

// Check which directories still exist
assert!(at.dir_exists("b/a/p")); // Should still exist (parent not writable)
Expand Down
Loading