dovecot-1.2: mkdir_parents() API was sometimes assumed to return...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Jul 20 23:03:39 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/b3efdd9dc293
changeset: 8034:b3efdd9dc293
user: Timo Sirainen <tss at iki.fi>
date: Sun Jul 20 23:03:09 2008 +0300
description:
mkdir_parents() API was sometimes assumed to return EEXIST and sometimes not.
Standardized it now so that the API does return EEXIST.
diffstat:
7 files changed, 21 insertions(+), 17 deletions(-)
src/lib-storage/index/dbox/dbox-file.c | 2 +-
src/lib-storage/index/mbox/mbox-storage.c | 4 ++--
src/lib-storage/list/mailbox-list-fs.c | 2 +-
src/lib-storage/list/subscription-file.c | 3 ++-
src/lib/mkdir-parents.c | 20 +++++++++++---------
src/lib/mkdir-parents.h | 5 +++--
src/plugins/fts-lucene/fts-backend-lucene.c | 2 +-
diffs (116 lines):
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib-storage/index/dbox/dbox-file.c
--- 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 @@ int dbox_file_move(struct dbox_file *fil
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;
}
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib-storage/index/mbox/mbox-storage.c
--- 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 @@ static const char *create_root_dir(bool
}
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 ma
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);
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib-storage/list/mailbox-list-fs.c
--- 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 @@ static int fs_list_rename_mailbox(struct
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;
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib-storage/list/subscription-file.c
--- 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 @@ int subsfile_set_subscribed(struct mailb
/* 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;
}
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib/mkdir-parents.c
--- 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 @@ int mkdir_parents(const char *path, mode
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 */
diff -r 38897ffeec2d -r b3efdd9dc293 src/lib/mkdir-parents.h
--- 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
diff -r 38897ffeec2d -r b3efdd9dc293 src/plugins/fts-lucene/fts-backend-lucene.c
--- 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 @@ static struct fts_backend *fts_backend_l
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;
}
More information about the dovecot-cvs
mailing list