Commit ddcd8544ed03d513d539a972b05a2c0140b48b90

Stefan Sperling 2019-03-11T19:57:53

move worktree-specific error handling out of got_path_mkdir()

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;
 }