# HG changeset patch # User J. Ali Harlow # Date 1412097175 -3600 # Node ID f969505e9265c7d6cdae0cd9dbe335915fd96d28 # Parent f3baf790a8150f4c8b860d64a40eaff40410632c razor_atomic_create_dir() shouldn't set mode of existing directories diff -r f3baf790a815 -r f969505e9265 librazor/atomic-actions.c --- a/librazor/atomic-actions.c Tue Sep 30 16:19:55 2014 +0100 +++ b/librazor/atomic-actions.c Tue Sep 30 18:12:55 2014 +0100 @@ -247,6 +247,7 @@ struct atomic_action *action) { mode_t mode; + struct stat buf; if (razor_atomic_in_error_state(atomic)) { atomic_action_free(action); @@ -256,16 +257,22 @@ mode = action->args.u.create_dir.mode & (S_IRWXU | S_IRWXG | S_IRWXO); if (!mkdir(action->args.path, mode)) - return 0; + return action; - if (errno != EEXIST || chmod(action->args.path, mode) < 0) { + if (errno != EEXIST || stat(action->args.path, &buf)) { if (!atomic->error) atomic->error = razor_error_new_posix(action->args.path); atomic_action_free(action); return NULL; } - return action; + if (!S_ISDIR(buf.st_mode) && !atomic->error) + atomic->error = razor_error_new_str(RAZOR_POSIX_ERROR, EEXIST, + action->args.path, + "Not a directory"); + + atomic_action_free(action); + return NULL; } static struct atomic_action *atomic_action_rmdir(struct razor_atomic *atomic, diff -r f3baf790a815 -r f969505e9265 librazor/atomic-none.c --- a/librazor/atomic-none.c Tue Sep 30 16:19:55 2014 +0100 +++ b/librazor/atomic-none.c Tue Sep 30 18:12:55 2014 +0100 @@ -98,13 +98,14 @@ if (stat(buffer, &buf) == 0) { if (!S_ISDIR(buf.st_mode)) { - atomic->error = razor_error_new_str(buffer, + atomic->error = razor_error_new_str(RAZOR_POSIX_ERROR, + EEXIST, + buffer, "Not a directory"); return -1; } } else if (mkdir(buffer, 0777) < 0) { - atomic->error = razor_error_new_str(buffer, - strerror(errno)); + atomic->error = razor_error_new_posix(buffer); return -1; } } @@ -140,7 +141,7 @@ free(buf); #else if (remove(path)) - atomic->error = razor_error_new_str(path, strerror(errno)); + atomic->error = razor_error_new_posix(path); #endif return razor_atomic_in_error_state(atomic); @@ -177,7 +178,7 @@ free(oldbuf); #else if (rename(oldpath, newpath)) - atomic->error = razor_error_new_str(newpath, strerror(errno)); + atomic->error = razor_error_new_posix(newpath); #endif return razor_atomic_in_error_state(atomic); @@ -187,19 +188,23 @@ razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname, mode_t mode) { + struct stat buf; + if (razor_atomic_in_error_state(atomic)) return -1; if (!mkdir(dirname, mode & (S_IRWXU | S_IRWXG | S_IRWXO))) return 0; - if (errno != EEXIST) { - atomic->error = razor_error_new_str(dirname, strerror(errno)); + if (errno != EEXIST || stat(dirname, &buf)) { + atomic->error = razor_error_new_posix(dirname); return -1; } - if (chmod(dirname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) { - atomic->error = razor_error_new_str(dirname, strerror(errno)); + if (!S_ISDIR(buf.st_mode)) { + atomic->error = razor_error_new_str(RAZOR_POSIX_ERROR, EEXIST, + action->args.path, + "Not a directory"); return -1; } @@ -215,13 +220,14 @@ #if HAVE_SYMLINK if (symlink(target, path) < 0) { - atomic->error = razor_error_new_str(path, strerror(errno)); + atomic->error = razor_error_new_posix(path); return -1; } return 0; #else - atomic->error = razor_error_new_str(NULL, + atomic->error = razor_error_new_str(RAZOR_GENERAL_ERROR, + RAZOR_GENERAL_ERROR_FAILED, NULL, "Symbolic links not supported " "on this platform"); @@ -242,7 +248,7 @@ mode & (S_IRWXU | S_IRWXG | S_IRWXO)); if (fd == -1) - atomic->error = razor_error_new_str(filename, strerror(errno)); + atomic->error = razor_error_new_posix(filename); return fd; }