Skip to content

Commit e1797f8

Browse files
derrickstoleemjcheetham
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 f0e01d8 commit e1797f8

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
@@ -1665,6 +1665,7 @@ static void my_create_tempfile(
16651665
struct strbuf buf = STRBUF_INIT;
16661666
int len_tp;
16671667
enum scld_error scld;
1668+
int retries;
16681669

16691670
gh__response_status__zero(status);
16701671

@@ -1713,7 +1714,15 @@ static void my_create_tempfile(
17131714
goto cleanup;
17141715
}
17151716

1717+
retries = 0;
17161718
*t1 = create_tempfile(buf.buf);
1719+
while (!*t1 && retries < 5) {
1720+
retries++;
1721+
strbuf_setlen(&buf, len_tp);
1722+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
1723+
*t1 = create_tempfile(buf.buf);
1724+
}
1725+
17171726
if (!*t1) {
17181727
strbuf_addf(&status->error_message,
17191728
"could not create tempfile: '%s'",
@@ -1735,6 +1744,13 @@ static void my_create_tempfile(
17351744
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);
17361745

17371746
*t2 = create_tempfile(buf.buf);
1747+
while (!*t2 && retries < 5) {
1748+
retries++;
1749+
strbuf_setlen(&buf, len_tp);
1750+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
1751+
*t2 = create_tempfile(buf.buf);
1752+
}
1753+
17381754
if (!*t2) {
17391755
strbuf_addf(&status->error_message,
17401756
"could not create tempfile: '%s'",

0 commit comments

Comments
 (0)