Skip to content

Commit

Permalink
Retry on checksum fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Aug 2, 2024
1 parent 9245bf2 commit 90f5227
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cargo-binstall/cargo-binstall
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ CHECKSUMS = {
"x86_64-unknown-linux-musl" => "d9f9876d9cc053827edb760775b9bacd091df70117c4d7f74b24f8f8749aa2b2",
"x86_64-pc-windows-msvc" => "96f8325693ed00ccb96c7ae0d1da83e9c1c644d33d87175d4d4594f71246f283",
"aarch64-apple-darwin" => "1cbc0ab3c12c3699379fb7f4640d194f71d4db2534d27b5c6849781920279721"
}

def infer_vendor
case RbConfig::CONFIG["host_os"]
when /linux/i
Expand Down Expand Up @@ -52,7 +50,7 @@ def tmpdir
@tmpdir ||= Dir.tmpdir
end

def download_and_save(triple)
def download_and_save(triple, attempts = 3)
checksum = CHECKSUMS.fetch(triple)
ext = triple.include?("linux") ? "tgz" : "zip"
url = "https://github.com/cargo-bins/cargo-binstall/releases/download/v#{CARGO_BINSTALL_VERSION}/cargo-binstall-#{triple}.#{ext}"
Expand Down Expand Up @@ -88,6 +86,14 @@ def download_and_save(triple)
ret = outfile
File.chmod(0o755, ret)
ret
rescue => e
if attempts > 0
warn("Error when downloading: #{e.message}, retrying in 3 seconds...")
sleep(3)
download_and_save(triple, attempts - 1)
else
raise
end
end

def install_cargo_binstall
Expand Down

0 comments on commit 90f5227

Please sign in to comment.