Skip to content

Commit 86cd8dc

Browse files
committed
Merge branch 'jh/loose-object-dirs-creation-race'
When two processes created one loose object file each, which fell into the same fan-out bucket that previously did not have any objects, they both tried to do an equivalent of mkdir .git/objects/$fanout && chmod $shared_perm .git/objects/$fanout before writing into their file .git/objects/$fanout/$remainder, one of which could have failed unnecessarily when the second invocation of mkdir found that the directory already has been created by the first one. * jh/loose-object-dirs-creation-race: sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs
2 parents 5bb6205 + b2476a6 commit 86cd8dc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sha1_file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,9 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
28572857
/* Make sure the directory exists */
28582858
memcpy(buffer, filename, dirlen);
28592859
buffer[dirlen-1] = 0;
2860-
if (mkdir(buffer, 0777) || adjust_shared_perm(buffer))
2860+
if (mkdir(buffer, 0777) && errno != EEXIST)
2861+
return -1;
2862+
if (adjust_shared_perm(buffer))
28612863
return -1;
28622864

28632865
/* Try again */

0 commit comments

Comments
 (0)