]> 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)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 12 Jul 2017 17:25:23 +0000 (20:25 +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 1bdc228f27f943ae94c6590527a3288189902cad..75d9259126ea73264264873ea4f3632f97bbb170 100644 (file)
@@ -2732,6 +2732,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);
 }