]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mailbox_create_missing_dir() - Handle mailbox delete race condition
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 12 Jul 2017 13:18:42 +0000 (16:18 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 12 Jul 2017 21:45:40 +0000 (00:45 +0300)
Make sure the directory isn't created if the mail root directory no longer
exists. This might happen during mailbox deletion when another process is
opening the mailbox at the same time.

src/lib-storage/mail-storage.c

index 37a2851c59a7bb7092fff8fe9cec88f8cce091e0..561d1d035643f50ac0e0bd7f22574480d5a5cbc9 100644 (file)
@@ -2725,6 +2725,15 @@ int mailbox_create_missing_dir(struct mailbox *box,
        if (stat(dir, &st) == 0)
                return 0;
 
+       if (null_strcmp(dir, mail_dir) != 0 &&
+           stat(mail_dir, &st) < 0 && (errno == ENOENT || errno == ENOTDIR)) {
+               /* Race condition - mail root directory doesn't exist
+                  anymore either. We shouldn't create this directory
+                  anymore. */
+               mailbox_set_deleted(box);
+               return -1;
+       }
+
        return mailbox_mkdir(box, dir, type);
 }