From 29588381dc714dbb3250da4ee4f172e775724257 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Mon, 19 Sep 2016 17:03:58 +0100 Subject: [PATCH 1/2] Retry on all curl errors, not just timeouts Otherwise random things cause downloading to fail when it might work on a retry. --- source/utils.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/utils.d b/source/utils.d index d04af076..3fa43096 100644 --- a/source/utils.d +++ b/source/utils.d @@ -352,7 +352,7 @@ in { assert (url.isRemote); } body { import core.time; - import std.net.curl : CurlTimeoutException, HTTP, FTP; + import std.net.curl : CurlException, HTTP, FTP; size_t onReceiveCb (File f, ubyte[] data) { @@ -377,7 +377,7 @@ body downloader.perform(); } logDebug ("Downloaded %s", url); - } catch (CurlTimeoutException e) { + } catch (CurlException e) { if (retryCount > 0) { logDebug ("Failed to download %s, will retry %d more %s", url, From 469182f8ba776ecfec404c15e9e033afeb6ac27b Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Tue, 20 Sep 2016 11:40:26 +0100 Subject: [PATCH 2/2] Synchronise downloading of files If multiple threads try to download the same file, then one of them will get an incomplete file since `downloadFile` will return early if the dest exists, which is does while the download is in progress. --- source/backends/debian/debpkg.d | 4 +++- source/backends/debian/debpkgindex.d | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/source/backends/debian/debpkg.d b/source/backends/debian/debpkg.d index 754f6592..7c8cc36e 100644 --- a/source/backends/debian/debpkg.d +++ b/source/backends/debian/debpkg.d @@ -62,7 +62,9 @@ public: @property string filename () const { if (debFname.isRemote) { immutable path = buildNormalizedPath (tmpDir, debFname.baseName); - downloadFile (debFname, path); + synchronized (this) { + downloadFile (debFname, path); + } return path; } return debFname; diff --git a/source/backends/debian/debpkgindex.d b/source/backends/debian/debpkgindex.d index a6005f86..9830b859 100644 --- a/source/backends/debian/debpkgindex.d +++ b/source/backends/debian/debpkgindex.d @@ -74,15 +74,17 @@ public: bool[string] ret; try { - const inReleaseContents = getFileContents (inRelease); + synchronized (this) { + const inReleaseContents = getFileContents (inRelease); - foreach (const ref entry; inReleaseContents) { - auto match = entry.matchFirst (translationregex); + foreach (const ref entry; inReleaseContents) { + auto match = entry.matchFirst (translationregex); - if (match.empty) - continue; + if (match.empty) + continue; - ret[match[1]] = true; + ret[match[1]] = true; + } } } catch (Exception ex) { logWarning ("Could not get %s, will assume 'en' is available.", inRelease); @@ -112,7 +114,9 @@ public: "Translation-%s.%s".format(lang, "%s")); try { - fname = downloadIfNecessary (rootDir, tmpDir, fullPath); + synchronized (this) { + fname = downloadIfNecessary (rootDir, tmpDir, fullPath); + } } catch (Exception ex) { logDebug ("No translations for %s in %s/%s", lang, suite, section); continue; @@ -175,7 +179,9 @@ public: { immutable path = buildPath ("dists", suite, section, "binary-%s".format (arch)); - return downloadIfNecessary (rootDir, tmpDir, buildPath (path, "Packages.%s")); + synchronized (this) { + return downloadIfNecessary (rootDir, tmpDir, buildPath (path, "Packages.%s")); + } } protected DebPackage newPackage (string name, string ver, string arch)