dovecot-1.1: lazy_expunge: When deleting mailboxes, if the desti...

dovecot at dovecot.org dovecot at dovecot.org
Thu Mar 5 01:31:29 EET 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/6137bc40962e
changeset: 8184:6137bc40962e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Mar 04 18:24:41 2009 -0500
description:
lazy_expunge: When deleting mailboxes, if the destination parent dir didn't exist, delete failed.

diffstat:

1 file changed, 25 insertions(+), 3 deletions(-)
src/plugins/lazy-expunge/lazy-expunge-plugin.c |   28 +++++++++++++++++++++---

diffs (51 lines):

diff -r 632777217f7b -r 6137bc40962e src/plugins/lazy-expunge/lazy-expunge-plugin.c
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Wed Mar 04 18:03:03 2009 -0500
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Wed Mar 04 18:24:41 2009 -0500
@@ -5,6 +5,7 @@
 #include "array.h"
 #include "str.h"
 #include "seq-range-array.h"
+#include "mkdir-parents.h"
 #include "maildir-storage.h"
 #include "mail-namespace.h"
 #include "lazy-expunge-plugin.h"
@@ -368,15 +369,36 @@ mailbox_move(struct mailbox_list *src_li
 	     struct mailbox_list *dest_list, const char **_dest_name)
 {
 	const char *dest_name = *_dest_name;
-	const char *srcdir, *src2dir, *src3dir, *destdir;
+	const char *srcdir, *src2dir, *src3dir, *destdir, *p, *destparent;
+	struct stat st;
 
 	srcdir = mailbox_list_get_path(src_list, src_name,
 				       MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	destdir = mailbox_list_get_path(dest_list, dest_name,
 					MAILBOX_LIST_PATH_TYPE_MAILBOX);
 	while (rename(srcdir, destdir) < 0) {
-		if (errno == ENOENT)
-			return 0;
+		if (errno == ENOENT) {
+			/* if this is because the destination parent directory
+			   didn't exist, create it. */
+			p = strrchr(destdir, '/');
+			if (p == NULL)
+				return 0;
+			destparent = t_strdup_until(destdir, p);
+			if (stat(destparent, &st) == 0)
+				return 0;
+
+			if (mkdir_parents(destparent, 0770) < 0) {
+				if (errno == EEXIST) {
+					/* race condition */
+					continue;
+				}
+				mailbox_list_set_critical(src_list,
+					"mkdir(%s) failed: %m", destparent);
+				return -1;
+			}
+			/* created, try again. */
+			continue;
+		}
 
 		if (!EDESTDIREXISTS(errno)) {
 			mailbox_list_set_critical(src_list,


More information about the dovecot-cvs mailing list