move worktree-specific error handling out of got_path_mkdir()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/lib/path.c b/lib/path.c
index e4c1921..569469b 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -298,22 +298,7 @@ got_path_mkdir(const char *abspath)
const struct got_error *err = NULL;
if (mkdir(abspath, GOT_DEFAULT_DIR_MODE) == -1) {
- struct stat sb;
-
- if (errno == EEXIST) {
- if (lstat(abspath, &sb) == -1) {
- err = got_error_from_errno();
- goto done;
- }
-
- if (!S_ISDIR(sb.st_mode)) {
- /* TODO directory is obstructed; do something */
- err = got_error(GOT_ERR_FILE_OBSTRUCTED);
- goto done;
- }
-
- return NULL;
- } else if (errno == ENOENT) {
+ if (errno == ENOENT) {
err = make_parent_dirs(abspath);
if (err)
goto done;
diff --git a/lib/worktree.c b/lib/worktree.c
index 5aff68d..8ce73ba 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -592,6 +592,16 @@ add_dir_on_disk(struct got_worktree *worktree, const char *path)
return got_error_from_errno();
err = got_path_mkdir(abspath);
+ if (err && err->code == GOT_ERR_ERRNO && errno == EEXIST) {
+ struct stat sb;
+ err = NULL;
+ if (lstat(abspath, &sb) == -1) {
+ err = got_error_from_errno();
+ } else if (!S_ISDIR(sb.st_mode)) {
+ /* TODO directory is obstructed; do something */
+ err = got_error(GOT_ERR_FILE_OBSTRUCTED);
+ }
+ }
free(abspath);
return err;
}