Skip to content

Commit f8166e0

Browse files
derrickstoleedscho
authored andcommitted
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". Signed-off-by: Derrick Stolee <[email protected]>
1 parent 2560448 commit f8166e0

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
@@ -1668,6 +1668,7 @@ static void my_create_tempfile(
16681668
struct strbuf buf = STRBUF_INIT;
16691669
int len_tp;
16701670
enum scld_error scld;
1671+
int retries;
16711672

16721673
gh__response_status__zero(status);
16731674

@@ -1716,7 +1717,15 @@ static void my_create_tempfile(
17161717
goto cleanup;
17171718
}
17181719

1720+
retries = 0;
17191721
*t1 = create_tempfile(buf.buf);
1722+
while (!*t1 && retries < 5) {
1723+
retries++;
1724+
strbuf_setlen(&buf, len_tp);
1725+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
1726+
*t1 = create_tempfile(buf.buf);
1727+
}
1728+
17201729
if (!*t1) {
17211730
strbuf_addf(&status->error_message,
17221731
"could not create tempfile: '%s'",
@@ -1738,6 +1747,13 @@ static void my_create_tempfile(
17381747
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);
17391748

17401749
*t2 = create_tempfile(buf.buf);
1750+
while (!*t2 && retries < 5) {
1751+
retries++;
1752+
strbuf_setlen(&buf, len_tp);
1753+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
1754+
*t2 = create_tempfile(buf.buf);
1755+
}
1756+
17411757
if (!*t2) {
17421758
strbuf_addf(&status->error_message,
17431759
"could not create tempfile: '%s'",

0 commit comments

Comments
 (0)