Skip to content

Commit

Permalink
safe_create_leading_directories: fix race that could give a false neg…
Browse files Browse the repository at this point in the history
…ative

If two processes are racing to create the same directory tree, they
will both see that the directory doesn't exist, both try to mkdir(),
and one of them will fail.  This is okay, as we only care that the
directory gets created.  So, we add a check for EEXIST from mkdir,
and continue when the directory exists, taking the same codepath as
the case where the earlier stat() succeeds and finds a directory.

Signed-off-by: Steven Walter <stevenrwalter@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Steven Walter authored and Junio C Hamano committed Mar 27, 2013
1 parent 7e20105 commit 928734d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,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 = '/';
Expand Down

0 comments on commit 928734d

Please sign in to comment.