Merge branch 'jh/loose-object-dirs-creation-race' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Dec 2013 19:32:50 +0000 (11:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Dec 2013 19:32:50 +0000 (11:32 -0800)
Two processes creating loose objects at the same time could have
failed unnecessarily when the name of their new objects started
with the same byte value, due to a race condition.

* jh/loose-object-dirs-creation-race:
sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs

sha1_file.c
index 9ae98c852c862679a064af34aa4d43141db7cc0c..760dd60031bc4de7f0155303da5938c1571a2378 100644 (file)
@@ -2860,7 +2860,9 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
                /* Make sure the directory exists */
                memcpy(buffer, filename, dirlen);
                buffer[dirlen-1] = 0;
-               if (mkdir(buffer, 0777) || adjust_shared_perm(buffer))
+               if (mkdir(buffer, 0777) && errno != EEXIST)
+                       return -1;
+               if (adjust_shared_perm(buffer))
                        return -1;
 
                /* Try again */