Commit 412de9a637e94b877c7762d90c87525f35018083

nulltoken 2010-12-20T10:43:23

Made gitfo_mkdir_recurs() gracefully recover when a given directory already exists.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/fileops.c b/src/fileops.c
index a25796a..f2a08e8 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -323,10 +323,15 @@ int gitfo_mkdir_recurs(const char *path, int mode)
     error = GIT_SUCCESS;
     pp = path_copy;
 
-    while (error == 0 && (sp = strchr(pp, '/')) != 0) {
+    while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != 0) {
         if (sp != pp && gitfo_isdir(path_copy) < GIT_SUCCESS) {
             *sp = 0;
             error = gitfo_mkdir(path_copy, mode);
+
+			/* Do not choke while trying to recreate an existing directory */
+			if (errno == EEXIST)
+				error = GIT_SUCCESS;
+
             *sp = '/';
         }