Clean up the downloaded file if it's corrupted

This commit is contained in:
Michael Droettboom 2019-03-13 15:01:35 -04:00
parent 584c61edc9
commit 04b7f73718
1 changed files with 8 additions and 4 deletions

View File

@ -42,10 +42,14 @@ def check_checksum(path, pkg):
def download_and_extract(buildpath, packagedir, pkg, args):
tarballpath = buildpath / Path(pkg['source']['url']).name
if not tarballpath.is_file():
subprocess.run([
'wget', '-q', '-O', str(tarballpath), pkg['source']['url']
], check=True)
check_checksum(tarballpath, pkg)
try:
subprocess.run([
'wget', '-q', '-O', str(tarballpath), pkg['source']['url']
], check=True)
check_checksum(tarballpath, pkg)
except Exception:
tarballpath.unlink()
raise
srcpath = buildpath / packagedir
if not srcpath.is_dir():
shutil.unpack_archive(str(tarballpath), str(buildpath))