mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Get a file during bootstrap to a temp location.
When downloading a file in the bootstrap phase - get it to a temp location first. Verify it there and only if downloaded properly move it to the `cache` directory. This should prevent `make` being stuck if the download was interrupted or otherwise corrupted. The temporary files are deleted in case of an exception.
This commit is contained in:
parent
9b63263d0d
commit
f5884f6824
@ -16,12 +16,26 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
def get(url, path, verbose=False):
|
def get(url, path, verbose=False):
|
||||||
print("downloading " + url)
|
|
||||||
sha_url = url + ".sha256"
|
sha_url = url + ".sha256"
|
||||||
sha_path = path + ".sha256"
|
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
||||||
for _url, _path in ((url, path), (sha_url, sha_path)):
|
temp_path = temp_file.name
|
||||||
|
sha_file = tempfile.NamedTemporaryFile(suffix=".sha256", delete=True)
|
||||||
|
sha_path = sha_file.name
|
||||||
|
download(sha_path, sha_url, temp_path, url, verbose)
|
||||||
|
verify(sha_path, temp_path, verbose)
|
||||||
|
sha_file.close()
|
||||||
|
print("moving " + temp_path + " to " + path)
|
||||||
|
shutil.move(temp_path, path)
|
||||||
|
temp_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def download(sha_path, sha_url, temp_path, url, verbose):
|
||||||
|
for _url, _path in ((url, temp_path), (sha_url, sha_path)):
|
||||||
|
print("downloading " + _url + " to " + _path)
|
||||||
# see http://serverfault.com/questions/301128/how-to-download
|
# see http://serverfault.com/questions/301128/how-to-download
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
run(["PowerShell.exe", "/nologo", "-Command",
|
run(["PowerShell.exe", "/nologo", "-Command",
|
||||||
@ -30,8 +44,11 @@ def get(url, path, verbose=False):
|
|||||||
verbose=verbose)
|
verbose=verbose)
|
||||||
else:
|
else:
|
||||||
run(["curl", "-o", _path, _url], verbose=verbose)
|
run(["curl", "-o", _path, _url], verbose=verbose)
|
||||||
print("verifying " + path)
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
|
def verify(sha_path, temp_path, verbose):
|
||||||
|
print("verifying " + temp_path)
|
||||||
|
with open(temp_path, "rb") as f:
|
||||||
found = hashlib.sha256(f.read()).hexdigest()
|
found = hashlib.sha256(f.read()).hexdigest()
|
||||||
with open(sha_path, "r") as f:
|
with open(sha_path, "r") as f:
|
||||||
expected, _ = f.readline().split()
|
expected, _ = f.readline().split()
|
||||||
@ -43,6 +60,7 @@ def get(url, path, verbose=False):
|
|||||||
raise RuntimeError(err)
|
raise RuntimeError(err)
|
||||||
sys.exit(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)
|
||||||
fname = os.path.basename(tarball).replace(".tar.gz", "")
|
fname = os.path.basename(tarball).replace(".tar.gz", "")
|
||||||
|
Loading…
Reference in New Issue
Block a user