struct atomic_action *action)
{
mode_t mode;
+ struct stat buf;
if (razor_atomic_in_error_state(atomic)) {
atomic_action_free(action);
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,
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;
}
}
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);
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);
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;
}
#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");
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;
}