[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
'rm -fr' mishandles unreadable empty directories
From: |
Paul Eggert |
Subject: |
'rm -fr' mishandles unreadable empty directories |
Date: |
Mon, 26 Jun 2006 01:08:04 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
(I found this while testing a new version of 'install-sh'.)
Here's a scenario illustrating the problem.
$ mkdir -m a-r -p a/b
$ rm -fr a
rm: cannot open directory `a/b': Permission denied
rm: cannot remove directory `a': Directory not empty
$ ls -ld a a/b
drwxr-xr-x 3 eggert eggert 4096 Jun 26 00:51 a
d-wx-wx-wx 2 eggert eggert 4096 Jun 26 00:51 a/b
My reading of POSIX is that, though a diagnostic is allowed here and
rm can exit with nonzero status because a/b is unreadable, "rm" is
still required to rmdir both a/b and a here, so this is a
POSIX-conformance issue.
Solaris 10 'rm' gets it right: when it discovers that "a/b" is
unreadable (openat fails) it tries rmdir("a/b"), and this works. No
diagnostics are issued.
This problem is in both coreutils 5.97 and CVS trunk.
One other test case:
$ mkdir -m 0 -p a/b
$ rm -fr a
rm: cannot chdir from `a' to `b': Permission denied
$ ls -ld a a/b
drwxr-xr-x 3 eggert eggert 4096 Jun 26 01:00 a
d--------- 2 eggert eggert 4096 Jun 26 01:00 a/b
This omits the "Directory not entry" diagnostic. It's a bit odd that
the diagnostic is omitted here but not for the first test case -- is
that intended?
- 'rm -fr' mishandles unreadable empty directories,
Paul Eggert <=