Skip to content

Commit

Permalink
build.d: Make download fail reliably
Browse files Browse the repository at this point in the history
`download` would sometimes return true on failure (caused by Issue 18318 which
requires additional work in dub). This commit implements a temporary workaround
and should be reverted when the issue is resolved.

See https://issues.dlang.org/show_bug.cgi?id=18318
  • Loading branch information
MoonlightSentinel committed Nov 18, 2019
1 parent 18652b5 commit 78e079b
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 78e079b

Please sign in to comment.