diff --git a/usr/lib/python3.6/vmmgr/pkgmgr.py b/usr/lib/python3.6/vmmgr/pkgmgr.py index b637fd0..fa1c57f 100644 --- a/usr/lib/python3.6/vmmgr/pkgmgr.py +++ b/usr/lib/python3.6/vmmgr/pkgmgr.py @@ -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)