From 91ee70ed04d33fecd7fc94621f236013d520d7b3 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 12 Jul 2017 16:18:42 +0300 Subject: [PATCH] lib-storage: mailbox_create_missing_dir() - Handle mailbox delete race condition 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 37a2851c59..561d1d0356 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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); } -- 2.47.3