Skip to content

Commit

Permalink
Merge pull request git-for-windows#205: gvfs-helper: fix race conditi…
Browse files Browse the repository at this point in the history
…on 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.
  • Loading branch information
derrickstolee authored Oct 4, 2019
2 parents 8f53588 + a9e428f commit db6fa76
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ static void create_tempfile_for_loose(
strbuf_complete(&buf_path, '/');
strbuf_add(&buf_path, hex, 2);

if (!file_exists(buf_path.buf) && mkdir(buf_path.buf, 0777) == -1) {
if (!file_exists(buf_path.buf) &&
mkdir(buf_path.buf, 0777) == -1 &&
!file_exists(buf_path.buf)) {
strbuf_addf(&status->error_message,
"cannot create directory for loose object '%s'",
buf_path.buf);
Expand Down

0 comments on commit db6fa76

Please sign in to comment.