rustbuild: Verify sha256 of downloaded tarballs
This commit is contained in:
parent
ffff91a8e8
commit
e0f997d347
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -18,13 +19,29 @@ import tarfile
|
||||||
|
|
||||||
def get(url, path, verbose=False):
|
def get(url, path, verbose=False):
|
||||||
print("downloading " + url)
|
print("downloading " + url)
|
||||||
# see http://serverfault.com/questions/301128/how-to-download
|
sha_url = url + ".sha256"
|
||||||
if sys.platform == 'win32':
|
sha_path = path + ".sha256"
|
||||||
run(["PowerShell.exe", "/nologo", "-Command",
|
for _url, _path in ((url, path), (sha_url, sha_path)):
|
||||||
"(New-Object System.Net.WebClient).DownloadFile('" + url +
|
# see http://serverfault.com/questions/301128/how-to-download
|
||||||
"', '" + path + "')"], verbose=verbose)
|
if sys.platform == 'win32':
|
||||||
else:
|
run(["PowerShell.exe", "/nologo", "-Command",
|
||||||
run(["curl", "-o", path, url], verbose=verbose)
|
"(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):
|
def unpack(tarball, dst, verbose=False, match=None):
|
||||||
print("extracting " + tarball)
|
print("extracting " + tarball)
|
||||||
|
|
Loading…
Reference in New Issue