Skip to content

Commit

Permalink
chore: ignore timestamps in zipfile (#184)
Browse files Browse the repository at this point in the history
Background: By defaut, zip files include timestamps of the files contained in the archive. As a result, two zip files can be identical in terms of their content, but differ in their checksum because the content timestamps are different.

Remove file timestamps from the zip archive, so that two zip files with the same contents have the same checksum. This can facilitate cache reuse in the backend.
  • Loading branch information
Aurélien Gasser authored Apr 13, 2021
1 parent 7839815 commit 9b78d82
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion substratest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def zip_folder(path, destination=None):
for f in files:
abspath = os.path.join(root, f)
archive_path = os.path.relpath(abspath, start=path)
zf.write(abspath, arcname=archive_path)
info = zipfile.ZipInfo.from_file(abspath, arcname=archive_path)
info.date_time = (1980, 1, 1, 0, 0, 0)
with open(abspath) as src:
zf.writestr(info, src.read())
return destination


Expand Down

0 comments on commit 9b78d82

Please sign in to comment.