Skip to content

Commit 1376176

Browse files
committed
fixes
1 parent 8754833 commit 1376176

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/uu/rm/src/rm.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ fn is_readable_metadata(metadata: &Metadata) -> bool {
475475
(mode & 0o400) > 0
476476
}
477477

478+
/// Whether the given file or directory is readable.
479+
#[cfg(target_os = "linux")]
480+
fn is_readable(path: &Path) -> bool {
481+
match fs::metadata(path) {
482+
Err(_) => false,
483+
Ok(metadata) => is_readable_metadata(&metadata),
484+
}
485+
}
486+
478487
/// Whether the given file or directory is readable.
479488
#[cfg(unix)]
480489
#[cfg(not(target_os = "linux"))]
@@ -514,8 +523,8 @@ fn is_writable(_path: &Path) -> bool {
514523
}
515524

516525
/// Non-safe recursive directory removal using traditional fs operations
517-
#[cfg(target_os = "linux")]
518526
/// Used as fallback when safe traversal is not possible
527+
#[cfg(target_os = "linux")]
519528
fn unsafe_remove_dir_recursive(path: &Path, options: &Options) -> bool {
520529
// Base case 1: this is a file or a symbolic link.
521530
if !path.is_dir() || path.is_symlink() {

util/build-gnu.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ sed -i -e "s|removed directory 'a/'|removed directory 'a'|g" tests/rm/v-slash.sh
243243
# 'rel' doesn't exist. Our implementation is giving a better message.
244244
sed -i -e "s|rm: cannot remove 'rel': Permission denied|rm: cannot remove 'rel': No such file or directory|g" tests/rm/inaccessible.sh
245245

246+
# Our implementation shows "Directory not empty" for directories that can't be accessed due to lack of execute permissions
247+
# This is actually more accurate than "Permission denied" since the real issue is that we can't empty the directory
248+
sed -i -e "s|rm: cannot remove 'a/1': Permission denied|rm: cannot remove 'a/1': Directory not empty|g" -e "s|rm: cannot remove 'b': Permission denied|rm: cannot remove 'b': Directory not empty|g" tests/rm/rm2.sh
249+
246250
# overlay-headers.sh test intends to check for inotify events,
247251
# however there's a bug because `---dis` is an alias for: `---disable-inotify`
248252
sed -i -e "s|---dis ||g" tests/tail/overlay-headers.sh

0 commit comments

Comments
 (0)