Skip to content

Commit 2491ae0

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 1166f60 commit 2491ae0

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
@@ -1675,6 +1675,7 @@ static void my_create_tempfile(
16751675
struct strbuf buf = STRBUF_INIT;
16761676
int len_tp;
16771677
enum scld_error scld;
1678+
int retries;
16781679

16791680
gh__response_status__zero(status);
16801681

@@ -1723,7 +1724,15 @@ static void my_create_tempfile(
17231724
goto cleanup;
17241725
}
17251726

1727+
retries = 0;
17261728
*t1 = create_tempfile(buf.buf);
1729+
while (!*t1 && retries < 5) {
1730+
retries++;
1731+
strbuf_setlen(&buf, len_tp);
1732+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1);
1733+
*t1 = create_tempfile(buf.buf);
1734+
}
1735+
17271736
if (!*t1) {
17281737
strbuf_addf(&status->error_message,
17291738
"could not create tempfile: '%s'",
@@ -1745,6 +1754,13 @@ static void my_create_tempfile(
17451754
strbuf_addf( &buf, "%s.%s", basename.buf, suffix2);
17461755

17471756
*t2 = create_tempfile(buf.buf);
1757+
while (!*t2 && retries < 5) {
1758+
retries++;
1759+
strbuf_setlen(&buf, len_tp);
1760+
strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2);
1761+
*t2 = create_tempfile(buf.buf);
1762+
}
1763+
17481764
if (!*t2) {
17491765
strbuf_addf(&status->error_message,
17501766
"could not create tempfile: '%s'",

0 commit comments

Comments
 (0)