Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autobuild/autobuild_tool_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Archive(InteractiveCommand):
ARGUMENTS = ['format', 'hash_algorithm', 'platform']

ARG_DICT = {'format': {'help': 'Archive format (e.g zip or tbz2)'},
'hash_algorithm': {'help': 'The algorithm for computing the archive hash (e.g. md5)'},
'hash_algorithm': {'help': 'The algorithm for computing the archive hash (e.g. md5, blake2b)'},
'platform': {'help': 'The name of the platform archive to be configured'}
}

Expand Down
15 changes: 6 additions & 9 deletions autobuild/autobuild_tool_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,15 @@ def _add_file_to_zip_archive(zip_file, unnormalized_file, archive_filename, adde


def _print_hash(filename: str, results: dict):
fp = open(filename, 'rb')
m = hashlib.md5()
while True:
d = fp.read(65536)
if not d:
break
m.update(d)
md5 = common.compute_md5(filename)
blake2b = common.compute_blake2b(filename)

# printing unconditionally on stdout for backward compatibility
# the Linden Lab build scripts no longer rely on this
# (they use the --results-file option instead)
print("md5 %s" % m.hexdigest())
results['autobuild_package_md5'] = m.hexdigest()
print("md5 %s" % md5)
results['autobuild_package_md5'] = md5
results['autobuild_package_blake2b'] = blake2b
# Not using logging, since this output should be produced unconditionally on stdout
# Downstream build tools utilize this output

19 changes: 19 additions & 0 deletions autobuild/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,25 @@ def compute_md5(path):
return hasher.hexdigest()


def compute_blake2b(path):
"""
Returns the blake2b sum for the given file.
"""
import hashlib

try:
stream = open(path, 'rb')
except IOError as err:
raise AutobuildError("Can't compute blake2b for %s: %s" % (path, err))

try:
hasher = hashlib.blake2b(stream.read())
finally:
stream.close()

return hasher.hexdigest()


def split_tarname(pathname):
"""
Given a tarfile pathname of the form:
Expand Down
5 changes: 5 additions & 0 deletions autobuild/hash_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ def verify_hash(hash_algorithm, pathname, hash):
@hash_algorithm("md5")
def _verify_md5(pathname, hash):
return common.compute_md5(pathname) == hash

@hash_algorithm("blake2b")
def _verify_blake2b(pathname, hash):
return common.compute_blake2b(pathname) == hash

4 changes: 3 additions & 1 deletion tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def test_results(self):
autobuild_package_platform="%s"
autobuild_package_filename="%s"
autobuild_package_md5="%s"
autobuild_package_blake2b="%s"
$''' % ('test1', re.escape(os.path.join(self.data_dir, "package-test", "autobuild-package.xml")),
"common", re.escape(self.tar_name), "[0-9a-f]{32}")
"common", re.escape(self.tar_name), "[0-9a-f]{32}", "[0-9a-f]{128}")
expected=re.compile(expected_results_regex, flags=re.MULTILINE)
assert os.path.exists(results_output), "results file not found: %s" % results_output
actual_results = open(results_output,'r').read()
Expand All @@ -125,6 +126,7 @@ def test_results_json(self):
self.assertEqual(results["autobuild_package_platform"], "common")
self.assertEqual(results["autobuild_package_filename"], self.tar_name)
self.assertEqual(len(results["autobuild_package_md5"]), 32)
self.assertEqual(len(results["autobuild_package_blake2b"]), 128)

def test_package_other_version(self):
# read the existing metadata file and update stored package version
Expand Down