GNU bug report logs -
#16669
rm: inconsistent 'rm -ir' prompting behavior (POSIX issue)
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On today's Austin Group call, we discussed
http://austingroupbugs.net/view.php?id=802 regarding 'rm' behavior.
They pointed out that GNU has an optimization not allowed by a strict
reading of the current standard:
$ mkdir foo
$ rm -ir foo
rm: remove directory ‘foo’?
Whether you answer yes or no, the point remains: rm only prompted once
about removing the empty directory. Compare that to other
implementations, such as Solaris:
$ rm -ir /tmp/foo
rm: examine files in directory /tmp/foo (yes/no)? y
rm: remove /tmp/foo (yes/no)? y
$
Note that the optimization implies that we did a readdir() on the
directory before deciding whether to prompt, in order to learn if it was
empty; and that readdir() modifies directory atime; in the Solaris
implementation, readdir() is not even attempted until after a positive
prompt response, which means directory atime is unchanged if the user
chooses not to descend.
Meanwhile, for a non-empty directory, we DO prompt twice for the directory:
$ touch foo/bar
$ rm -ir foo
rm: descend into directory ‘foo’? y
rm: remove regular empty file ‘foo/bar’? y
rm: remove directory ‘foo’?
Here, we get the POSIX-mandated double prompting, once to descend, and
once after recursion is complete to see whether to remove the now-empty
directory. The argument is whether the GNU optimization of prompting
only once for an empty directory violates POSIX (and where it is
observable by a new directory atime), or whether we should patch POSIX
to allow the GNU optimization. In the meeting, I ended up with an
action item to right the bug report against POSIX to propose wording
that would allow the GNU behavior.
Conversely, consider:
$ rm -ir foo
rm: descend into directory ‘foo’? y
rm: remove regular empty file ‘foo/bar’? n
rm: remove directory ‘foo’? y
rm: cannot remove ‘foo’: Directory not empty
Why on earth are we prompting to remove 'foo' when we KNOW it is
non-empty because the user specifically asked to not remove foo/bar? If
we can optimize from two prompts down to one for the empty directory
case, why are we not optimizing and avoiding asking a useless prompt for
a known non-empty directory? So, while writing my POSIX bug report,
should I also allow for an optimization of omitting the second prompt
for a known non-empty directory (known because of a negative answer to
prompts on its children), even though GNU does not yet implement that
optimization?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 6 years and 240 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.