Skip to content

Commit

Permalink
Merge pull request #10590 from MoonlightSentinel/build-download
Browse files Browse the repository at this point in the history
build.d: Make download fail reliably
  • Loading branch information
thewilsonator committed Nov 19, 2019
2 parents 18652b5 + 78e079b commit e0cc6f6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/build.d
Expand Up @@ -1073,25 +1073,25 @@ Returns: `true` if download succeeded
*/
bool download(string to, string from, uint tries = 3)
{
import std.net.curl : download, HTTPStatusException;
import std.net.curl : download, HTTP, HTTPStatusException;

foreach(i; 0..tries)
{
try
{
log("Downloading %s ...", from);
download(from, to);
return true;
auto con = HTTP(from);
download(from, to, con);

if (con.statusLine.code == 200)
return true;
}
catch(HTTPStatusException e)
{
if (e.status == 404) throw e;
else
{
log("Failed to download %s (Attempt %s of %s)", from, i + 1, tries);
continue;
}
}

log("Failed to download %s (Attempt %s of %s)", from, i + 1, tries);
}

return false;
Expand Down

0 comments on commit e0cc6f6

Please sign in to comment.