bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ".." anomaly in "rmdir -p"?


From: Eric Blake
Subject: Re: ".." anomaly in "rmdir -p"?
Date: Fri, 24 Aug 2007 08:14:50 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Juergen Reuter on 8/24/2007 7:47 AM:
> rmdir -p dir2/../dir1
> 
> (which after expansion denotes the same directory) then you get the
> error message "dir2/..: Directory not empty", probably since ".." is
> handled like an ordinary directory segment specifier.

Ahh, but dir1 WAS deleted, as requested.  It was only when rmdir moved on
to the next section, "dir2/..", that a failure was detected.

> I wonder, if rmdir should remove by file path expansion all occurrences
> of ".." and "." from the path before taking any further action.  This
> would avoid the above annoying behavior.  Or does the Posix standard
> demand the current behavior?

Thanks for the report.  You are correct that POSIX requires the behavior:
http://www.opengroup.org/onlinepubs/009695399/utilities/rmdir.html

However, GNU rm also provides the --ignore-fail-on-non-empty option, which
silences the message that you found annoying.  And if you want to rely
only on standardized features, then this idiom works pretty well in
makefiles when $(directory) might contain ..:

rmdir -p $(directory) 2>/dev/null || :

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGzufY84KuGfSFAYARAgWCAJ9ttJkMTHKmnt9ZRCdvj6ow8anWKQCfRMKh
3aOxq9b1sZS4NEiFyd6nClM=
=o/Y1
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]