]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added MAILBOX_LIST_FLAG_OPTIONAL_BOXES flag.
authorTimo Sirainen <tss@iki.fi>
Fri, 4 Nov 2011 18:36:06 +0000 (20:36 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 4 Nov 2011 18:36:06 +0000 (20:36 +0200)
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mailbox-list.h

index fc50e8ac155779c944ad71941657e991bc2bd525..d52d0a7a42ef903b2f2b825af9c3a85f5afa9eee 100644 (file)
@@ -316,46 +316,54 @@ static const char *mailbox_list_fs_get_trash_dir(struct mailbox_list *list)
        return t_strdup_printf("%s/"MAILBOX_LIST_FS_TRASH_DIR_NAME, root_dir);
 }
 
-static int fs_list_delete_mailbox(struct mailbox_list *list, const char *name)
+static int
+fs_list_delete_maildir(struct mailbox_list *list, const char *name)
 {
        const char *path, *trash_dir;
-       int ret = 0;
-
-       if ((list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) != 0) {
-               if (mailbox_list_delete_mailbox_file(list, name) < 0)
-                       return -1;
-               ret = 1;
-       }
+       bool rmdir_path;
+       int ret;
 
        if (*list->set.maildir_name != '\0' &&
-           *list->set.mailbox_dir_name != '\0' && ret == 0) {
+           *list->set.mailbox_dir_name != '\0') {
                trash_dir = mailbox_list_fs_get_trash_dir(list);
                ret = mailbox_list_delete_maildir_via_trash(list, name,
                                                            trash_dir);
                if (ret < 0)
                        return -1;
 
-               /* try to delete the parent directory */
-               path = mailbox_list_get_path(list, name,
-                                            MAILBOX_LIST_PATH_TYPE_DIR);
-               if (rmdir(path) < 0 && errno != ENOENT &&
-                   errno != ENOTEMPTY && errno != EEXIST) {
-                       mailbox_list_set_critical(list, "rmdir(%s) failed: %m",
-                                                 path);
+               if (ret > 0) {
+                       /* try to delete the parent directory */
+                       path = mailbox_list_get_path(list, name,
+                                                    MAILBOX_LIST_PATH_TYPE_DIR);
+                       if (rmdir(path) < 0 && errno != ENOENT &&
+                           errno != ENOTEMPTY && errno != EEXIST) {
+                               mailbox_list_set_critical(list,
+                                       "rmdir(%s) failed: %m", path);
+                       }
+                       return 0;
                }
        }
 
-       if (ret == 0) {
-               bool rmdir_path = *list->set.maildir_name != '\0';
+       rmdir_path = *list->set.maildir_name != '\0';
+       path = mailbox_list_get_path(list, name,
+                                    MAILBOX_LIST_PATH_TYPE_MAILBOX);
+       return mailbox_list_delete_mailbox_nonrecursive(list, name, path,
+                                                       rmdir_path);
+}
 
-               path = mailbox_list_get_path(list, name,
-                                            MAILBOX_LIST_PATH_TYPE_MAILBOX);
-               if (mailbox_list_delete_mailbox_nonrecursive(list, name, path,
-                                                            rmdir_path) < 0)
-                       return -1;
+static int fs_list_delete_mailbox(struct mailbox_list *list, const char *name)
+{
+       int ret;
+
+       if ((list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) != 0) {
+               ret = mailbox_list_delete_mailbox_file(list, name);
+       } else {
+               ret = fs_list_delete_maildir(list, name);
        }
-       mailbox_list_delete_finish(list, name);
-       return 0;
+
+       if (ret == 0 || (list->flags & MAILBOX_LIST_FLAG_OPTIONAL_BOXES) != 0)
+               mailbox_list_delete_finish(list, name);
+       return ret;
 }
 
 static int fs_list_rmdir(struct mailbox_list *list, const char *name,
index 71a8ea654b33c0197e3a75aafc241809560814bc..2da8e26a66d2102d18c762547e1f386289853abf 100644 (file)
@@ -402,16 +402,17 @@ maildir_list_delete_maildir(struct mailbox_list *list, const char *name)
 static int
 maildir_list_delete_mailbox(struct mailbox_list *list, const char *name)
 {
+       int ret;
+
        if ((list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) != 0) {
-               if (mailbox_list_delete_mailbox_file(list, name) < 0)
-                       return -1;
+               ret = mailbox_list_delete_mailbox_file(list, name);
        } else {
-               if (maildir_list_delete_maildir(list, name) < 0)
-                       return -1;
+               ret = maildir_list_delete_maildir(list, name);
        }
 
-       mailbox_list_delete_finish(list, name);
-       return 0;
+       if (ret == 0 || (list->flags & MAILBOX_LIST_FLAG_OPTIONAL_BOXES) != 0)
+               mailbox_list_delete_finish(list, name);
+       return ret;
 }
 
 static int maildir_list_delete_dir(struct mailbox_list *list, const char *name)
index e47f37cc758d4ac3a9a76a73ffae49d1fc6c09fd..0d625fda0adeacf3d45b26e6f24c85df05bdc1f8 100644 (file)
@@ -32,7 +32,11 @@ enum mailbox_list_flags {
        MAILBOX_LIST_FLAG_MAILBOX_FILES         = 0x01,
        /* Namespace already has a mailbox list, don't assign this
           mailbox list to it. */
-       MAILBOX_LIST_FLAG_SECONDARY             = 0x02
+       MAILBOX_LIST_FLAG_SECONDARY             = 0x02,
+       /* Don't assume that just because a mailbox directory doesn't exist
+          its index/control directories don't exist (e.g. this is index-only
+          mailbox list) */
+       MAILBOX_LIST_FLAG_OPTIONAL_BOXES        = 0x04
 };
 
 enum mailbox_info_flags {