Skip to content

Commit

Permalink
Merge pull request git-for-windows#231: gvfs-helper: retry when creat…
Browse files Browse the repository at this point in the history
…ing temp files

When we create temp files for downloading packs, we use a name
based on the current timestamp. There is no randomness in the
name, so we can have collisions in the same second.

Retry the temp pack names using a new "-<retry>" suffix to the
name before the ".temp".

This is a follow-up to git-for-windows#229.
  • Loading branch information
derrickstolee authored Dec 31, 2019
2 parents b0b2793 + 789f5dd commit ccc87aa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ static void my_create_tempfile(
struct strbuf buf = STRBUF_INIT;
int len_tp;
enum scld_error scld;
int retries;

gh__response_status__zero(status);

Expand Down Expand Up @@ -1701,7 +1702,15 @@ static void my_create_tempfile(
goto cleanup;
}

retries = 0;
*t1 = create_tempfile(buf.buf);
while (!*t1 && retries < 5) {
retries++;
strbuf_setlen(&buf, len_tp);
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
*t1 = create_tempfile(buf.buf);
}

if (!*t1) {
strbuf_addf(&status->error_message,
"could not create tempfile: '%s'",
Expand All @@ -1723,6 +1732,13 @@ static void my_create_tempfile(
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);

*t2 = create_tempfile(buf.buf);
while (!*t2 && retries < 5) {
retries++;
strbuf_setlen(&buf, len_tp);
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
*t2 = create_tempfile(buf.buf);
}

if (!*t2) {
strbuf_addf(&status->error_message,
"could not create tempfile: '%s'",
Expand Down

0 comments on commit ccc87aa

Please sign in to comment.