diff -r cf499fd51df7 -r 4b7270fd3201 librazor/atomic-none.c --- a/librazor/atomic-none.c Sat Aug 23 16:07:09 2014 +0100 +++ b/librazor/atomic-none.c Thu Apr 14 11:59:56 2016 +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; }