diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py index fb8a87adb..a5956055e 100755 --- a/win_toolchain/get_toolchain_if_necessary.py +++ b/win_toolchain/get_toolchain_if_necessary.py @@ -183,8 +183,12 @@ def CalculateHash(root, expected_hash): digest.update(f.read()) # Save the timestamp file if the calculated hash is the expected one. - if digest.hexdigest() == expected_hash: + # The expected hash may be shorter, to reduce path lengths, in which case just + # compare that many characters. + if expected_hash and digest.hexdigest()[:len(expected_hash)] == expected_hash: SaveTimestampsAndHash(root, digest.hexdigest()) + # Return the (potentially truncated) expected_hash. + return expected_hash return digest.hexdigest() diff --git a/win_toolchain/package_from_installed.py b/win_toolchain/package_from_installed.py index 6794f955b..d3c3f23f4 100644 --- a/win_toolchain/package_from_installed.py +++ b/win_toolchain/package_from_installed.py @@ -424,6 +424,10 @@ def RenameToSha1(output): zf.extractall(rel_dir) print('Hashing...') sha1 = get_toolchain_if_necessary.CalculateHash(rel_dir, None) + # Shorten from forty characters to ten. This is still enough to avoid + # collisions, while being less unwieldy and reducing the risk of MAX_PATH + # failures. + sha1 = sha1[:10] os.chdir(old_dir) shutil.rmtree(tempdir) final_name = sha1 + '.zip'