-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assets: file order in zip archive is inconsistent #2759
Comments
Interesting. Another problem with zip archives is when you have some kind of build step generating files in the directory to be zipped: even if the generated content is exactly the same, the hash of the zip file will change because the creation date/times are updated. |
You are right, this is another problem. One alternate approach would be to calculate the hash of an asset based on the md5 of every file in the asset's directory. I'm not sure what would be the performance impact (for directory hierarchies containing a large number of files, or large files) for CDK users though. |
Or find a way to zip a directory and have all file timestamps in it set to Epoch. |
I believe our archiver already neuters the timestamps (setting them to some fixed date far in the past, although not Epoch because this causes problems on some certain versions of certain platforms -- looking at you, Windows). It would be worth writing a test that confirms this is the case however... As well as ensuring files are listed in alphabetical order, so the files are consistent. |
From the output above ( |
Describe the bug
When the assets module builds zip archives, file order in the zip file is inconsistent, resulting in variations in calculated hashes of the zip files. This causes unexpected uploads of assets to S3, which, in turn, might update CDK resources (Lambda functions, Lambda layers) that use those assets.
To Reproduce
Run the following:
Assuming that
myDir
is a directory containing more than 1 file, running the above script will print differing hashes. Here's an example:Note how the order of the files in
a.zip
differs fromb.zip
.Expected behavior
Creating many zip archives of the same directory should yield consistent hashes.
Version:
The text was updated successfully, but these errors were encountered: