Skip to content

Commit 4b0160c

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 <dstolee@microsoft.com>
1 parent e144498 commit 4b0160c

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
@@ -1662,6 +1662,7 @@ static void my_create_tempfile(
16621662
struct strbuf buf = STRBUF_INIT;
16631663
int len_tp;
16641664
enum scld_error scld;
1665+
int retries;
16651666

16661667
gh__response_status__zero(status);
16671668

@@ -1710,7 +1711,15 @@ static void my_create_tempfile(
17101711
goto cleanup;
17111712
}
17121713

1714+
retries = 0;
17131715
*t1 = create_tempfile(buf.buf);
1716+
while (!*t1 && retries < 5) {
1717+
retries++;
1718+
strbuf_setlen(&buf, len_tp);
1719+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
1720+
*t1 = create_tempfile(buf.buf);
1721+
}
1722+
17141723
if (!*t1) {
17151724
strbuf_addf(&status->error_message,
17161725
"could not create tempfile: '%s'",
@@ -1732,6 +1741,13 @@ static void my_create_tempfile(
17321741
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);
17331742

17341743
*t2 = create_tempfile(buf.buf);
1744+
while (!*t2 && retries < 5) {
1745+
retries++;
1746+
strbuf_setlen(&buf, len_tp);
1747+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
1748+
*t2 = create_tempfile(buf.buf);
1749+
}
1750+
17351751
if (!*t2) {
17361752
strbuf_addf(&status->error_message,
17371753
"could not create tempfile: '%s'",

0 commit comments

Comments
 (0)