Re: Reliable/safe way of removing empty maildirs?
On Thu, Dec 06, 2007 at 11:40:04AM -0500, Paul Hoffman wrote:
> On Thu, Dec 06, 2007 at 10:03:20AM -0600, Kyle Wheeler wrote:
> > On Thursday, December 6 at 04:46 PM, quoth Rado S:
> > >=- Chris G wrote on Thu 6.Dec'07 at 13:03:13 +0000 -=
> > >
> > >> What's a reliable way of removing empty maildirs?
> > >> Presumably it's possible but you'd have to follow some protocol that
> > >> wouldn't interfere with the proper writing of messages to the maildir.
> > >
> > >chmod a-w dir/new
> > >rm -rf dir
> >
> > Well, that's not *quite* safe, now is it? There's a race condition
> > between deciding that a maildir is empty and then changing the
> > permissions such that no one can deliver mail to it. It would have to
> > be more like this:
> >
> > chmod a-w dir/new
> > if [ `find dir -type f` ] ; then
>
> You have to do something like this instead:
>
> found=`find dir -type f`
> if -n "$found" ; then
Ack! Sorry, I meant:
if [ -n "$found" ]; then
> At least on my system (Mac OS X 10.3 = Darwin 7.9.0), where find(1)
> exits with status 0 even if nothing is found.
>
> > echo "Not empty!"
> > chmod a+w dir/new
> > else
> > rm -rf dir
> > fi
> >
> > ~Kyle
>
> Paul.
Paul.
--
Paul Hoffman <nkuitse@xxxxxxxxxxx>