<<< Date Index >>>     <<< Thread Index >>>

Re: Reliable/safe way of removing empty maildirs?



On Fri, Dec 07, 2007 at 05:37:45PM +1100, Cameron Simpson wrote:
> On 06Dec2007 21:15, A Darren Dunham <ddunham@xxxxxxxx> wrote:
> | > >> chmod a-w dir/new
> | > >> if [ `find dir -type f` ] ; then
> | > >
> | > > You have to do something like this instead:
> | [snip other responses]
> | 
> | Perhaps I've misunderstood the reason for doing this, but I would just
> | ask find to do a rmdir, and let it fail if the directory isn't empty.
> | 
> | find dir -depth -type d -exec rmdir {} \;
> | 
> | If 'dir' is still around when that finishes, it's probably because
> | there's a file in there now.  In the meantime, it's removed all empty
> | subtrees.
> 
> Yeah, but without even invoking find:
> 
>   rmdir dir/new dir/tmp dir/cur dir \
>   || mkdir -p dir/new dir/tmp dir/cur
> 
> Robust, safe, trivial.
> 
> People always seem to forget that rmdir is perfectly safe, in that it
> won't remove empty directories.
> 
Now that's quite clever!  :-)   Can anyone see anything wrong with it?

-- 
Chris Green