Skip to content

Commit db6fa76

Browse files
Merge pull request #205: gvfs-helper: fix race condition when creating loose object dirs
When two gvfs-helper processes are the first to create a loose object directory, the processes (A and B in the timeline below) could have the following race: 1. A sees that the directory does not exist. 2. B sees that the directory does not exist. 3. A creates the directory with success. 4. B fails to create the directory and fails. Instead of having B fail here, just check for the directory's existence before reporting an error. That solves the race and allows tests to pass.
2 parents 8f53588 + a9e428f commit db6fa76

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gvfs-helper.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,9 @@ static void create_tempfile_for_loose(
10491049
strbuf_complete(&buf_path, '/');
10501050
strbuf_add(&buf_path, hex, 2);
10511051

1052-
if (!file_exists(buf_path.buf) && mkdir(buf_path.buf, 0777) == -1) {
1052+
if (!file_exists(buf_path.buf) &&
1053+
mkdir(buf_path.buf, 0777) == -1 &&
1054+
!file_exists(buf_path.buf)) {
10531055
strbuf_addf(&status->error_message,
10541056
"cannot create directory for loose object '%s'",
10551057
buf_path.buf);

0 commit comments

Comments
 (0)