Skip to content
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

fix: prefer to set mod time to oldest allowed by zip #93

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shouze
Copy link

@shouze shouze commented Apr 12, 2021

What does it fix?

zip files generated by this plugin are great because if we produce a zip file of the same files in two distinct points in time it will produce a zip archive with exactly the same resulting hash ❤️.

But... in go time.Time{} is the zero time, the documentation if very clear on it:

The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC

This leads to 2 major issues:

  1. For many zip unarchivers (see note below), the oldest supported time is 1980-01-01 0:00 UTC so we potentialy generate archives not supported by any zip unarchiver 🤐.
  2. On my Linux system at least, the files once unarchived on my local file system have dates in 2049, so in the future. And I can tell you that it leads some of my AWS lambda to crash when I distribute them through a zip created by this plugin 💥.

Notes

As spotted in https://www.mindprod.com/jgloss/zip.html:

The format does not support dates prior to 1980-01-01 0:00 UTC . Avoid file dates 1980-01-01 or earlier (local or UTC time).

I'm not sur to generate the given date the best way that can be done in go, by the way I've tested the compiled module on a real situation and it fixes the issue I'm facing 😉.

@ghost ghost added the size/XS label Apr 12, 2021
@hashicorp-cla
Copy link

hashicorp-cla commented Apr 12, 2021

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


Sébastien HOUZÉ seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA.
If you have already a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

@shouze
Copy link
Author

shouze commented Apr 12, 2021

ping @appilon or @kmoe would love your feedback 💯

@shouze shouze closed this Apr 12, 2021
@shouze shouze changed the title fix: prefer to set mod time to oldes allowed by zip fix: prefer to set mod time to oldest allowed by zip Apr 12, 2021
@shouze shouze reopened this Apr 12, 2021
Copy link
Member

@kmoe kmoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - this looks like a very sensible fix!

zip#FileHeader.SetModTime() is marked as deprecated in the stdlib docs in favour of setting FileHeader.Modified directly. Judging by recent changes to archive/zip I think it's worth switching to FileHeader.Modified so we can remove the "fh.Modified alone isn't enough when using a zero value" comment added in #16.

Please also add an acceptance test that checks the modified time of the archived file. You could add this to TestZipArchiver_FileModified or make a new test.

@shouze shouze force-pushed the fix-prefer-setting-modtime-to-oldest-allowed-by-zip branch from df8215f to 5ce1bea Compare July 21, 2021 20:48
Sébastien HOUZÉ added 3 commits July 21, 2021 22:49
As spotted in https://www.mindprod.com/jgloss/zip.html

> The format does not support dates prior to 1980-01-01 0:00 UTC . Avoid file dates 1980-01-01 or earlier (local or UTC time).
@shouze shouze force-pushed the fix-prefer-setting-modtime-to-oldest-allowed-by-zip branch from 5ce1bea to 273acc9 Compare July 21, 2021 20:50
@shouze
Copy link
Author

shouze commented Jul 21, 2021

Thanks - this looks like a very sensible fix!

zip#FileHeader.SetModTime() is marked as deprecated in the stdlib docs in favour of setting FileHeader.Modified directly. Judging by recent changes to archive/zip I think it's worth switching to FileHeader.Modified so we can remove the "fh.Modified alone isn't enough when using a zero value" comment added in #16.

Please also add an acceptance test that checks the modified time of the archived file. You could add this to TestZipArchiver_FileModified or make a new test.

@kmoe I've made all requested changes, LGTM?

@kmoe kmoe added this to the v3.0.0 milestone Jul 27, 2021
@kmoe kmoe self-assigned this Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants