Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/npm/client.py
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | def _prepare_package_version(self, package_source_data, version_data): | ||||
expected_digest = package_source_data['sha1'] | expected_digest = package_source_data['sha1'] | ||||
actual_digest = hashes['sha1'] | actual_digest = hashes['sha1'] | ||||
if actual_digest != expected_digest: | if actual_digest != expected_digest: | ||||
raise ValueError( | raise ValueError( | ||||
'%s %s: Checksum mismatched: %s != %s' % ( | '%s %s: Checksum mismatched: %s != %s' % ( | ||||
self.package, version, expected_digest, actual_digest)) | self.package, version, expected_digest, actual_digest)) | ||||
# uncompress tarball | # uncompress tarball | ||||
tarball_invalid = False | |||||
try: | |||||
tarball.uncompress(filepath, path) | tarball.uncompress(filepath, path) | ||||
except Exception: | |||||
tarball_invalid = True | |||||
# remove tarball | # remove tarball | ||||
os.remove(filepath) | os.remove(filepath) | ||||
if tarball_invalid: | |||||
return (None, None, None, None) | |||||
# do not archive useless tarball root directory | # do not archive useless tarball root directory | ||||
package_path = os.path.join(path, 'package') | package_path = os.path.join(path, 'package') | ||||
# some old packages use a root directory with a different name | # some old packages use a root directory with a different name | ||||
if not os.path.exists(package_path): | if not os.path.exists(package_path): | ||||
for _, dirnames, _ in os.walk(path): | for _, dirnames, _ in os.walk(path): | ||||
if dirnames: | if dirnames: | ||||
package_path = os.path.join(path, dirnames[0]) | package_path = os.path.join(path, dirnames[0]) | ||||
break | break | ||||
Show All 23 Lines |