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

Re: How to implement save_empty on maildir?



Hi,

* Derek Martin wrote:

> On Thu, Jul 02, 2009 at 08:10:21AM +0000, Jörg Sommer wrote:
> > So, create the directory yourself to ensure it's there and yours.
> > 
> > % cat rename-test.c
> > #include <stdio.h>
> > #include <sys/stat.h>
> > 
> > int main(void)
> > {
> >     mkdir("mdir-mutt-delete", 0)  /* this is a temporary directory to
> >                                      ensure rename doesn't replace an
> >                                      existing directory */
> > 
> >       || rename("mdir", "mdir-mutt-delete");
> > 
> >     return 0;
> > }

This an example to outline a proposed solution, I know, but how about
mkdtemp()? Hard-coded temporary file/directory names beg for trouble.

> There are several problems with this.  If the directory exists when
> you do the mkdir, it fails with no clear course of action to take to
> fix the failure; that seems like clearly a bug to me.  Also, if some
> process puts a file in mdir-mutt-delete before you rename it, the
> rename will fail.  In either case, Mutt didn't do what you told it to
> do (remove the maildir when it's empty).  You can't code stuff that
> works sometimes in applications that other people are going to use...

I think you also get strange semantics if a messages is
delivered/appended to 'mdir' between the mkdir() and rename() calls?
Both calls would succeed but you would fail to remove
'mdir-mutt-delete'.

Rocco

Attachment: pgpxqDLt1HPOD.pgp
Description: PGP signature