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
This commit is contained in:
Junio C Hamano 2013-12-05 12:54:14 -08:00
commit 86cd8dc8e7

View File

@ -2857,7 +2857,9 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
/* Make sure the directory exists */ /* Make sure the directory exists */
memcpy(buffer, filename, dirlen); memcpy(buffer, filename, dirlen);
buffer[dirlen-1] = 0; 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; return -1;
/* Try again */ /* Try again */