Skip to content

Commit 9cc6b21

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 0d5e773 commit 9cc6b21

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
@@ -1667,6 +1667,7 @@ static void my_create_tempfile(
16671667
struct strbuf buf = STRBUF_INIT;
16681668
int len_tp;
16691669
enum scld_error scld;
1670+
int retries;
16701671

16711672
gh__response_status__zero(status);
16721673

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

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

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

0 commit comments

Comments
 (0)