changeset 22329:f2e7b5010810

lib-storage: Improve MAILBOX_LIST_PROP_AUTOCREATE_DIRS related comments
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 12 Jul 2017 16:15:13 +0300
parents a86e10e8e8a3
children ac8ac56cab89
files src/lib-storage/mail-storage.c src/lib-storage/mailbox-list.h
diffstat 2 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Tue Jul 11 14:14:47 2017 +0300
+++ b/src/lib-storage/mail-storage.c	Wed Jul 12 16:15:13 2017 +0300
@@ -2708,10 +2708,16 @@
 	if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX,
 				&mail_dir) < 0)
 		return -1;
-	if (null_strcmp(dir, mail_dir) == 0) {
-		if ((box->list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) == 0)
-			return 0;
-		/* the directory might not have been created yet */
+	if (null_strcmp(dir, mail_dir) != 0) {
+		/* Mailbox directory is different - create a missing dir */
+	} else if ((box->list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) != 0) {
+		/* This layout (e.g. imapc) wants to autocreate missing mailbox
+		   directories as well. */
+	} else {
+		/* If the mailbox directory doesn't exist, the mailbox
+		   shouldn't exist at all. So just assume that it's already
+		   created and if there's a race condition just fail later. */
+		return 0;
 	}
 
 	/* we call this function even when the directory exists, so first do a
--- a/src/lib-storage/mailbox-list.h	Tue Jul 11 14:14:47 2017 +0300
+++ b/src/lib-storage/mailbox-list.h	Wed Jul 12 16:15:13 2017 +0300
@@ -23,7 +23,9 @@
 	MAILBOX_LIST_PROP_NO_NOSELECT		= 0x04,
 	/* mail root directory isn't required */
 	MAILBOX_LIST_PROP_NO_ROOT		= 0x08,
-	/* Automatically create mailbox directories when needed */
+	/* Automatically create mailbox directories when needed. Normally it's
+	   assumed that if a mailbox directory doesn't exist, the mailbox
+	   doesn't exist either. */
 	MAILBOX_LIST_PROP_AUTOCREATE_DIRS	= 0x10
 };