Merge branch 'jk/check-corrupt-objects-carefully'
[gitweb.git] / sha1_file.c
index 0b99f336e62256606f3fffc3eaf0ee7727d428c5..0ed23981b363a07c6f4c5b930b1a5991d5c8a622 100644 (file)
@@ -124,8 +124,13 @@ int safe_create_leading_directories(char *path)
                        }
                }
                else if (mkdir(path, 0777)) {
-                       *pos = '/';
-                       return -1;
+                       if (errno == EEXIST &&
+                           !stat(path, &st) && S_ISDIR(st.st_mode)) {
+                               ; /* somebody created it since we checked */
+                       } else {
+                               *pos = '/';
+                               return -1;
+                       }
                }
                else if (adjust_shared_perm(path)) {
                        *pos = '/';