Skip to content

Commit 3b9ff2a

Browse files
committed
Merge pull request git-for-windows#231: gvfs-helper: retry when creating 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.
2 parents 32f5baf + 94fa1d0 commit 3b9ff2a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gvfs-helper.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ static void my_create_tempfile(
16531653
struct strbuf buf = STRBUF_INIT;
16541654
int len_tp;
16551655
enum scld_error scld;
1656+
int retries;
16561657

16571658
gh__response_status__zero(status);
16581659

@@ -1701,7 +1702,15 @@ static void my_create_tempfile(
17011702
goto cleanup;
17021703
}
17031704

1705+
retries = 0;
17041706
*t1 = create_tempfile(buf.buf);
1707+
while (!*t1 && retries < 5) {
1708+
retries++;
1709+
strbuf_setlen(&buf, len_tp);
1710+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
1711+
*t1 = create_tempfile(buf.buf);
1712+
}
1713+
17051714
if (!*t1) {
17061715
strbuf_addf(&status->error_message,
17071716
"could not create tempfile: '%s'",
@@ -1723,6 +1732,13 @@ static void my_create_tempfile(
17231732
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);
17241733

17251734
*t2 = create_tempfile(buf.buf);
1735+
while (!*t2 && retries < 5) {
1736+
retries++;
1737+
strbuf_setlen(&buf, len_tp);
1738+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
1739+
*t2 = create_tempfile(buf.buf);
1740+
}
1741+
17261742
if (!*t2) {
17271743
strbuf_addf(&status->error_message,
17281744
"could not create tempfile: '%s'",

0 commit comments

Comments
 (0)