diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index cf12f3c..39d0249 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -185,13 +185,30 @@ void fetchPackage(Path path, string packageId, Dependency dep, bool pre_release) { import std.array : replace; + import std.net.curl : CurlException; Json best = getBestPackage(packageId, dep, pre_release); if (best.type == Json.Type.null_) return; auto vers = best["version"].get!string; auto url = m_registryUrl ~ Path(PackagesPath~"/"~packageId~"/"~vers~".zip"); logDiagnostic("Downloading from '%s'", url); - download(url, path); + foreach(i; 0..3) { + try{ + download(url, path); + return; + } + catch(HTTPStatusException e) { + if (e.status == 404) { + logDebug("Failed to download package %s from %s (404)", packageId, url); + return; + } + else { + logDebug("Failed to download package %s from %s (Attempt %s of 3)", packageId, url, i + 1); + continue; + } + } + } + throw new Exception("Failed to download package %s from %s".format(packageId, url)); } Json fetchPackageRecipe(string packageId, Dependency dep, bool pre_release) @@ -214,14 +231,24 @@ logDebug("Getting from %s", url); string jsonData; - try - jsonData = cast(string)download(url); - catch (HTTPStatusException e) - { - if (e.status != 404) - throw e; - logDebug("Package %s not found in %s: %s", packageId, description, e.msg); - return Json(null); + foreach(i; 0..3) { + try { + jsonData = cast(string)download(url); + break; + } + catch (HTTPStatusException e) + { + if (e.status == 404) { + logDebug("Package %s not found in %s (404): %s", packageId, description, e.msg); + return Json(null); + } + else { + logDebug("Package %s not found in %s (attempt %s of 3): %s", packageId, description, i + 1, e.msg); + if (i == 2) + throw e; + continue; + } + } } Json json = parseJsonString(jsonData, url.toString()); // strip readme data (to save size and time)