]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Handle rmdir() failing with EEXIST the same as failing with ENOTEMPTY.
authorTimo Sirainen <tss@iki.fi>
Mon, 12 Jul 2010 14:14:45 +0000 (15:14 +0100)
committerTimo Sirainen <tss@iki.fi>
Mon, 12 Jul 2010 14:14:45 +0000 (15:14 +0100)
This is allowed by POSIX, and at least Solaris does that.

src/lib-storage/list/mailbox-list-delete.c
src/lib-storage/list/mailbox-list-fs.c
src/lib/unlink-directory.c

index 3598dadc89f7b9fa77e62e05d19dd3b5c0a4079c..9671af4f785c85d88d152c0a4190a737f12b6ec2 100644 (file)
@@ -219,7 +219,8 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list,
        if (rmdir_path) {
                if (rmdir(path) == 0)
                        unlinked_something = TRUE;
-               else if (errno != ENOENT && errno != ENOTEMPTY) {
+               else if (errno != ENOENT &&
+                        errno != ENOTEMPTY && errno != EEXIST) {
                        mailbox_list_set_critical(list, "rmdir(%s) failed: %m",
                                                  path);
                        return -1;
@@ -260,7 +261,7 @@ void mailbox_list_delete_until_root(struct mailbox_list *list, const char *path,
        }
        while (strcmp(path, root_dir) != 0) {
                if (rmdir(path) < 0 && errno != ENOENT) {
-                       if (errno == ENOTEMPTY)
+                       if (errno == ENOTEMPTY || errno == EEXIST)
                                return;
 
                        mailbox_list_set_critical(list, "rmdir(%s) failed: %m",
index 2261e53dfc5ad9af747acf855165bc16f3cf168b..0df5fd238bd1fc6dede42dd6c168c3139575c429 100644 (file)
@@ -391,7 +391,8 @@ static int fs_list_delete_mailbox(struct mailbox_list *list, const char *name)
                /* 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) {
+               if (rmdir(path) < 0 && errno != ENOENT &&
+                   errno != ENOTEMPTY && errno != EEXIST) {
                        mailbox_list_set_critical(list, "rmdir(%s) failed: %m",
                                                  path);
                }
@@ -435,7 +436,7 @@ static int fs_list_delete_dir(struct mailbox_list *list, const char *name)
        if (errno == ENOENT) {
                mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
                        T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
-       } else if (errno == ENOTEMPTY) {
+       } else if (errno == ENOTEMPTY || errno == EEXIST) {
                /* mbox workaround: if only .imap/ directory is preventing the
                   deletion, remove it */
                child_name = t_strdup_printf("%s%cchild", name,
@@ -479,8 +480,8 @@ static int rename_dir(struct mailbox_list *oldlist, const char *oldname,
        }
        if (rmdir_parent && (p = strrchr(oldpath, '/')) != NULL) {
                oldpath = t_strdup_until(oldpath, p);
-               if (rmdir(oldpath) < 0 &&
-                   errno != ENOENT && errno != ENOTEMPTY) {
+               if (rmdir(oldpath) < 0 && errno != ENOENT &&
+                   errno != ENOTEMPTY && errno != EEXIST) {
                        mailbox_list_set_critical(oldlist,
                                "rmdir(%s) failed: %m", oldpath);
                }
@@ -603,7 +604,8 @@ static int fs_list_rename_mailbox(struct mailbox_list *oldlist,
                                                MAILBOX_LIST_PATH_TYPE_DIR);
                if (rmdir(oldpath) == 0)
                        rmdir_parent = TRUE;
-               else if (errno != ENOENT && errno != ENOTEMPTY) {
+               else if (errno != ENOENT &&
+                        errno != ENOTEMPTY && errno != EEXIST) {
                        mailbox_list_set_critical(oldlist,
                                "rmdir(%s) failed: %m", oldpath);
                }
index dc4b3cf776a77490f41bc2248fd60e45afab064b..5dc3c74acf75fc4a032759dabca594551e194c2a 100644 (file)
@@ -117,8 +117,13 @@ static int unlink_directory_r(const char *dir)
                                        break;
 
                                if (rmdir(d->d_name) < 0) {
-                                       if (errno != ENOENT)
+                                       if (errno != ENOENT) {
+                                               if (errno == EEXIST) {
+                                                       /* standardize errno */
+                                                       errno = ENOTEMPTY;
+                                               }
                                                break;
+                                       }
                                        errno = 0;
                                }
                        } else {
@@ -169,8 +174,13 @@ int unlink_directory(const char *dir, bool unlink_dir)
        }
 
        if (unlink_dir) {
-               if (rmdir(dir) < 0 && errno != ENOENT)
+               if (rmdir(dir) < 0 && errno != ENOENT) {
+                       if (errno == EEXIST) {
+                               /* standardize errno */
+                               errno = ENOTEMPTY;
+                       }
                        return -1;
+               }
        }
 
        return 0;