From 1c677fdfdba831c525f0abc45063a045f18ad644 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 26 Dec 2019 10:20:24 -0500 Subject: [PATCH] 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 "-" suffix to the name before the ".temp". Signed-off-by: Derrick Stolee --- gvfs-helper.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gvfs-helper.c b/gvfs-helper.c index 3cc4ae68dc..a32fa413ca 100644 --- a/gvfs-helper.c +++ b/gvfs-helper.c @@ -1653,6 +1653,7 @@ static void my_create_tempfile( struct strbuf buf = STRBUF_INIT; int len_tp; enum scld_error scld; + int retries; gh__response_status__zero(status); @@ -1701,7 +1702,15 @@ static void my_create_tempfile( goto cleanup; } + retries = 0; *t1 = create_tempfile(buf.buf); + while (!*t1 && retries < 5) { + retries++; + strbuf_setlen(&buf, len_tp); + strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix1); + *t1 = create_tempfile(buf.buf); + } + if (!*t1) { strbuf_addf(&status->error_message, "could not create tempfile: '%s'", @@ -1723,6 +1732,13 @@ static void my_create_tempfile( strbuf_addf( &buf, "%s.%s", basename.buf, suffix2); *t2 = create_tempfile(buf.buf); + while (!*t2 && retries < 5) { + retries++; + strbuf_setlen(&buf, len_tp); + strbuf_addf(&buf, "%s-%d.%s", basename.buf, retries, suffix2); + *t2 = create_tempfile(buf.buf); + } + if (!*t2) { strbuf_addf(&status->error_message, "could not create tempfile: '%s'",