1.1 --- a/librazor/atomic-none.c Sat Aug 23 16:07:09 2014 +0100
1.2 +++ b/librazor/atomic-none.c Fri Oct 03 15:05:33 2014 +0100
1.3 @@ -98,13 +98,14 @@
1.4
1.5 if (stat(buffer, &buf) == 0) {
1.6 if (!S_ISDIR(buf.st_mode)) {
1.7 - atomic->error = razor_error_new_str(buffer,
1.8 + atomic->error = razor_error_new_str(RAZOR_POSIX_ERROR,
1.9 + EEXIST,
1.10 + buffer,
1.11 "Not a directory");
1.12 return -1;
1.13 }
1.14 } else if (mkdir(buffer, 0777) < 0) {
1.15 - atomic->error = razor_error_new_str(buffer,
1.16 - strerror(errno));
1.17 + atomic->error = razor_error_new_posix(buffer);
1.18 return -1;
1.19 }
1.20 }
1.21 @@ -140,7 +141,7 @@
1.22 free(buf);
1.23 #else
1.24 if (remove(path))
1.25 - atomic->error = razor_error_new_str(path, strerror(errno));
1.26 + atomic->error = razor_error_new_posix(path);
1.27 #endif
1.28
1.29 return razor_atomic_in_error_state(atomic);
1.30 @@ -177,7 +178,7 @@
1.31 free(oldbuf);
1.32 #else
1.33 if (rename(oldpath, newpath))
1.34 - atomic->error = razor_error_new_str(newpath, strerror(errno));
1.35 + atomic->error = razor_error_new_posix(newpath);
1.36 #endif
1.37
1.38 return razor_atomic_in_error_state(atomic);
1.39 @@ -187,19 +188,23 @@
1.40 razor_atomic_create_dir(struct razor_atomic *atomic, const char *dirname,
1.41 mode_t mode)
1.42 {
1.43 + struct stat buf;
1.44 +
1.45 if (razor_atomic_in_error_state(atomic))
1.46 return -1;
1.47
1.48 if (!mkdir(dirname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)))
1.49 return 0;
1.50
1.51 - if (errno != EEXIST) {
1.52 - atomic->error = razor_error_new_str(dirname, strerror(errno));
1.53 + if (errno != EEXIST || stat(dirname, &buf)) {
1.54 + atomic->error = razor_error_new_posix(dirname);
1.55 return -1;
1.56 }
1.57
1.58 - if (chmod(dirname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
1.59 - atomic->error = razor_error_new_str(dirname, strerror(errno));
1.60 + if (!S_ISDIR(buf.st_mode)) {
1.61 + atomic->error = razor_error_new_str(RAZOR_POSIX_ERROR, EEXIST,
1.62 + action->args.path,
1.63 + "Not a directory");
1.64 return -1;
1.65 }
1.66
1.67 @@ -215,13 +220,14 @@
1.68
1.69 #if HAVE_SYMLINK
1.70 if (symlink(target, path) < 0) {
1.71 - atomic->error = razor_error_new_str(path, strerror(errno));
1.72 + atomic->error = razor_error_new_posix(path);
1.73 return -1;
1.74 }
1.75
1.76 return 0;
1.77 #else
1.78 - atomic->error = razor_error_new_str(NULL,
1.79 + atomic->error = razor_error_new_str(RAZOR_GENERAL_ERROR,
1.80 + RAZOR_GENERAL_ERROR_FAILED, NULL,
1.81 "Symbolic links not supported "
1.82 "on this platform");
1.83
1.84 @@ -242,7 +248,7 @@
1.85 mode & (S_IRWXU | S_IRWXG | S_IRWXO));
1.86
1.87 if (fd == -1)
1.88 - atomic->error = razor_error_new_str(filename, strerror(errno));
1.89 + atomic->error = razor_error_new_posix(filename);
1.90
1.91 return fd;
1.92 }