Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8034:b3efdd9dc293 HEAD
mkdir_parents() API was sometimes assumed to return EEXIST and sometimes not.
Standardized it now so that the API does return EEXIST.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 20 Jul 2008 23:03:09 +0300 |
parents | 38897ffeec2d |
children | ed12eee73357 |
files | 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 |
diffstat | 7 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-file.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib-storage/index/dbox/dbox-file.c Sun Jul 20 23:03:09 2008 +0300 @@ -1240,7 +1240,7 @@ 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; }
--- a/src/lib-storage/index/mbox/mbox-storage.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Jul 20 23:03:09 2008 +0300 @@ -265,7 +265,7 @@ } 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 @@ 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);
--- a/src/lib-storage/list/mailbox-list-fs.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib-storage/list/mailbox-list-fs.c Sun Jul 20 23:03:09 2008 +0300 @@ -293,7 +293,7 @@ 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;
--- a/src/lib-storage/list/subscription-file.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib-storage/list/subscription-file.c Sun Jul 20 23:03:09 2008 +0300 @@ -101,7 +101,8 @@ /* 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; }
--- a/src/lib/mkdir-parents.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib/mkdir-parents.c Sun Jul 20 23:03:09 2008 +0300 @@ -10,16 +10,18 @@ const char *p; int ret; - /* EISDIR check is for BSD/OS which returns it if path contains '/' - at the end and it exists. + 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 (mkdir(path, mode) < 0 && errno != EEXIST && - errno != EISDIR && errno != ENOSYS) { - if (errno != ENOENT) - return -1; - + 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 */
--- a/src/lib/mkdir-parents.h Sun Jul 20 22:00:13 2008 +0300 +++ b/src/lib/mkdir-parents.h Sun Jul 20 23:03:09 2008 +0300 @@ -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
--- a/src/plugins/fts-lucene/fts-backend-lucene.c Sun Jul 20 22:00:13 2008 +0300 +++ b/src/plugins/fts-lucene/fts-backend-lucene.c Sun Jul 20 23:03:09 2008 +0300 @@ -57,7 +57,7 @@ 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; }