]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mkdir_parents() API was sometimes assumed to return EEXIST and sometimes not.
authorTimo Sirainen <tss@iki.fi>
Sun, 20 Jul 2008 20:03:09 +0000 (23:03 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 20 Jul 2008 20:03:09 +0000 (23:03 +0300)
Standardized it now so that the API does return EEXIST.

--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-file.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/subscription-file.c
src/lib/mkdir-parents.c
src/lib/mkdir-parents.h
src/plugins/fts-lucene/fts-backend-lucene.c

index 8765cd6583ed2c6749af93c4d023e7d236b2dc10..7a0c6548dfa7c3a90efad59a17be9e9b4dd6b94c 100644 (file)
@@ -1240,7 +1240,7 @@ int dbox_file_move(struct dbox_file *file, bool alt_path)
           since we really don't want to break the file. */
        out_fd = open(temp_path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
        if (out_fd == -1 && errno == ENOENT) {
-               if (mkdir_parents(dest_dir, 0700) < 0) {
+               if (mkdir_parents(dest_dir, 0700) < 0 && errno != EEXIST) {
                        i_error("mkdir_parents(%s) failed: %m", dest_dir);
                        return -1;
                }
index b4ce350f3bb06c728d7f5c14e11f478bc5b23593..85f07d67a7d65bdaf62c84c4cc50d0a6923ad630 100644 (file)
@@ -265,7 +265,7 @@ static const char *create_root_dir(bool debug, const char **error_r)
        }
 
        path = t_strconcat(home, "/mail", NULL);
-       if (mkdir_parents(path, CREATE_MODE) < 0) {
+       if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) {
                *error_r = t_strdup_printf("mkdir(%s) failed: %m", path);
                return NULL;
        }
@@ -719,7 +719,7 @@ static int mbox_mailbox_create(struct mail_storage *_storage, const char *name,
        p = directory ? path + strlen(path) : strrchr(path, '/');
        if (p != NULL) {
                p = t_strdup_until(path, p);
-               if (mkdir_parents(p, CREATE_MODE) < 0) {
+               if (mkdir_parents(p, CREATE_MODE) < 0 && errno != EEXIST) {
                        if (!mail_storage_set_error_from_errno(_storage)) {
                                mail_storage_set_critical(_storage,
                                        "mkdir_parents(%s) failed: %m", p);
index a3c4baaa5bdb9eea119efd3844dc718533a40a9c..da62552c566f26b0ff7f0bf6651f138f11fa6131 100644 (file)
@@ -293,7 +293,7 @@ static int fs_list_rename_mailbox(struct mailbox_list *list,
        p = strrchr(newpath, '/');
        if (p != NULL) {
                p = t_strdup_until(newpath, p);
-               if (mkdir_parents(p, CREATE_MODE) < 0) {
+               if (mkdir_parents(p, CREATE_MODE) < 0 && errno != EEXIST) {
                        if (mailbox_list_set_error_from_errno(list))
                                return -1;
 
index d8d7ab7f4e2944d53c1e5c96d0f42aa45af839fd..69c5fff5c8b3ee1d63d86aebf682707c5320038a 100644 (file)
@@ -101,7 +101,8 @@ int subsfile_set_subscribed(struct mailbox_list *list, const char *path,
                /* directory hasn't been created yet. */
                p = strrchr(path, '/');
                dir = p == NULL ? NULL : t_strdup_until(path, p);
-               if (dir != NULL && mkdir_parents(dir, 0700) < 0) {
+               if (dir != NULL && mkdir_parents(dir, 0700) < 0 &&
+                   errno != EEXIST) {
                        subsfile_set_syscall_error(list, "mkdir()", dir);
                        return -1;
                }
index c81dd8bbf8bfcefda8db9c27619438ff0b10c0bd..19563cf9edf087d6b575f8b347de0dc52f5a54ec 100644 (file)
@@ -10,16 +10,18 @@ int mkdir_parents(const char *path, mode_t mode)
        const char *p;
        int ret;
 
-       /* EISDIR check is for BSD/OS which returns it if path contains '/'
-          at the end and it exists.
-
-          ENOSYS check is for NFS mount points.
-       */
-       if (mkdir(path, mode) < 0 && errno != EEXIST &&
-           errno != EISDIR && errno != ENOSYS) {
-               if (errno != ENOENT)
-                       return -1;
-
+       if (mkdir(path, mode) == 0) {
+               /* success */
+       } else if (errno != ENOENT) {
+               /* EISDIR check is for BSD/OS which returns it if path
+                  contains '/' at the end and it exists.
+
+                  ENOSYS check is for NFS mount points.
+               */
+               if (errno == EISDIR && errno == ENOSYS)
+                       errno = EEXIST;
+               return -1;
+       } else {
                p = strrchr(path, '/');
                if (p == NULL || p == path)
                        return -1; /* shouldn't happen */
index 4cf592b72628e1acd00df8bb11bea58fc17f4734..975033164fce3ea1269cc4db2544a8c7633be675 100644 (file)
@@ -1,8 +1,9 @@
 #ifndef MKDIR_PARENTS_H
 #define MKDIR_PARENTS_H
 
-/* Create path and all the directories under it if needed.
-   Returns 0 if ok, or if path already exists (not necessarily as directory). */
+/* Create path and all the directories under it if needed. Permissions for
+   existing directories isn't changed. Returns 0 if ok. If directory already
+   exists, returns -1 with errno=EXIST. */
 int mkdir_parents(const char *path, mode_t mode);
 
 #endif
index 99c5a3408a94af6cc32757952df5538d0249bb87..77e0866b53eac5e7b9dac674bca9c299c999565e 100644 (file)
@@ -57,7 +57,7 @@ static struct fts_backend *fts_backend_lucene_init(struct mailbox *box)
 
                path = t_strconcat(path, "/"LUCENE_INDEX_DIR_NAME, NULL);
                lock_path = t_strdup_printf("%s/"LUCENE_LOCK_SUBDIR_NAME, path);
-               if (mkdir_parents(lock_path, 0700) < 0) {
+               if (mkdir_parents(lock_path, 0700) < 0 && errno != EEXIST) {
                        i_error("mkdir_parents(%s) failed: %m", lock_path);
                        return NULL;
                }