Standardized it now so that the API does return EEXIST.
--HG--
branch : HEAD
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;
}
}
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;
}
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);
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;
/* 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;
}
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 */
#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
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;
}