Don't re-download already verified packages after interrupted installations
This commit is contained in:
parent
d64e57ba69
commit
27cb356d92
@ -79,20 +79,28 @@ class PkgMgr:
|
||||
|
||||
def download_package(self, name, item):
|
||||
# Download tar.xz package and verify its hash. Can raise InvalidSignature
|
||||
pkg_filename = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release'])
|
||||
res = self.get_repo_resource(pkg_filename, True)
|
||||
tmp_archive = os.path.join('/tmp', pkg_filename)
|
||||
with open(tmp_archive, 'wb') as f:
|
||||
pkg_archive = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release'])
|
||||
tmp_archive = os.path.join('/tmp', pkg_archive)
|
||||
# If the archive already exists in temp (presumably because the previous installation was interrupted), it was already verified and can be reused
|
||||
if os.path.exists(tmp_archive):
|
||||
item.bytes_downloaded += os.path.getsize(tmp_archive)
|
||||
return
|
||||
# Download the archive
|
||||
partial_archive = '{}.partial'.format(tmp_archive)
|
||||
res = self.get_repo_resource(pkg_archive, True)
|
||||
with open(partial_archive, 'wb') as f:
|
||||
for chunk in res.iter_content(chunk_size=65536):
|
||||
if chunk:
|
||||
item.bytes_downloaded += f.write(chunk)
|
||||
# Verify hash
|
||||
crypto.verify_hash(tmp_archive, self.online_packages[name]['sha512'])
|
||||
crypto.verify_hash(partial_archive, self.online_packages[name]['sha512'])
|
||||
# Remove ".partial" extension
|
||||
os.rename(partial_archive, tmp_archive)
|
||||
|
||||
def unpack_package(self, name):
|
||||
# Unpack archive
|
||||
pkg_filename = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release'])
|
||||
tmp_archive = os.path.join('/tmp', pkg_filename)
|
||||
pkg_archive = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release'])
|
||||
tmp_archive = os.path.join('/tmp', pkg_archive)
|
||||
subprocess.run(['tar', 'xJf', tmp_archive], cwd='/', check=True)
|
||||
os.unlink(tmp_archive)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user