mirror of
https://github.com/git/git.git
synced 2024-10-28 21:07:52 +01:00
safe_create_leading_directories: fix race that could give a false negative
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>
This commit is contained in:
parent
7e2010537e
commit
928734d993
1 changed files with 7 additions and 2 deletions
|
@ -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 = '/';
|
||||
|
|
Loading…
Reference in a new issue