Skip to content

Commit 37ba4c6

Browse files
committed
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
2 parents c5f05b2 + 928734d commit 37ba4c6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sha1_file.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ int safe_create_leading_directories(char *path)
124124
}
125125
}
126126
else if (mkdir(path, 0777)) {
127-
*pos = '/';
128-
return -1;
127+
if (errno == EEXIST &&
128+
!stat(path, &st) && S_ISDIR(st.st_mode)) {
129+
; /* somebody created it since we checked */
130+
} else {
131+
*pos = '/';
132+
return -1;
133+
}
129134
}
130135
else if (adjust_shared_perm(path)) {
131136
*pos = '/';

0 commit comments

Comments
 (0)