Skip to content

Commit

Permalink
rustbuild: Verify sha256 of downloaded tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
caipre committed Apr 14, 2016
1 parent ffff91a commit e0f997d
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/bootstrap/bootstrap.py
Expand Up @@ -10,6 +10,7 @@

import argparse
import contextlib
import hashlib
import os
import shutil
import subprocess
Expand All @@ -18,13 +19,29 @@

def get(url, path, verbose=False):
print("downloading " + url)
# see http://serverfault.com/questions/301128/how-to-download
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"(New-Object System.Net.WebClient).DownloadFile('" + url +
"', '" + path + "')"], verbose=verbose)
else:
run(["curl", "-o", path, url], verbose=verbose)
sha_url = url + ".sha256"
sha_path = path + ".sha256"
for _url, _path in ((url, path), (sha_url, sha_path)):
# see http://serverfault.com/questions/301128/how-to-download
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"(New-Object System.Net.WebClient)"
".DownloadFile('{}', '{}')".format(_url, _path)],
verbose=verbose)
else:
run(["curl", "-o", _path, _url], verbose=verbose)
print("verifying " + path)
with open(path, "rb") as f:
found = hashlib.sha256(f.read()).hexdigest()
with open(sha_path, "r") as f:
expected, _ = f.readline().split()
if found != expected:
err = ("invalid checksum:\n"
" found: {}\n"
" expected: {}".format(found, expected))
if verbose:
raise RuntimeError(err)
sys.exit(err)

def unpack(tarball, dst, verbose=False, match=None):
print("extracting " + tarball)
Expand Down

0 comments on commit e0f997d

Please sign in to comment.