summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2013-04-02 15:09:48 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-04-02 15:09:48 -0700
commit37ba4c61d04d0782bd34971be5cc4eec10f59d36 (patch)
tree1a8e81ea59a5015e9aa532eaaae39520fbe4ebe2
parentMerge branch 'bk/document-commit-tree-S' (diff)
parentsafe_create_leading_directories: fix race that could give a false negative (diff)
downloadtgif-37ba4c61d04d0782bd34971be5cc4eec10f59d36.tar.xz
Merge branch 'sw/safe-create-leading-dir-race'
* sw/safe-create-leading-dir-race: safe_create_leading_directories: fix race that could give a false negative
-rw-r--r--sha1_file.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 16967d3b9a..5f573d9b81 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -124,8 +124,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 = '/';