-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Use writestr to zip files with mtime before 1980 #2646
Conversation
I don't feel this should be necessary. Uglify-JS needs to release a fix for Edit: the reason I don't feel this should be needed here is because this is only going to patch ONE issue caused by these broken timestamps. The underying issue should be fixed rather than trying to patch every possible thing out there that doesn't handle epoch 0 timestamps. |
I'm -1 on modifying files without explicit consent. Maybe if there is a command line flag to opt in to this behavior, but even then I'm still hesitant to deliberately upload obviously corrupted files. With |
Agreed with @eric-tucker and @JordonPhillips I would rather the user be alerted their file is corrupted rather than paint over it. |
I also agree, we shouldn't be modifying someone's files, even one as minor as changing the mtime, without their knowledge or consent. |
(Just catching up on this now). I suppose I have a basic question. Why is the CLI
|
Well, zip files don't natively support it, the spec explicitly says the modification time is indicated by years since 1980. Zip files do support extra metadata being stored, so maybe the zip utility is storing the real mtime as an extra field? |
Instead of 'touching' source files, in order to avoid 1980 timestamp errors
Codecov Report
@@ Coverage Diff @@
## develop #2646 +/- ##
===========================================
- Coverage 95.56% 95.53% -0.04%
===========================================
Files 151 151
Lines 11798 11805 +7
===========================================
+ Hits 11275 11278 +3
- Misses 523 527 +4
Continue to review full report at Codecov.
|
Seems like I failed to realize that modifying the timestamp was a big deal. I rewrote the whole thing, instead of modifying the timestamp in the source file, I switched to writestr [1] which adds the file to the zip with the current time. The only caveat is that the whole file is read into memory before adding it to the zip, but I don't think that should be a big deal under most circumstances. [1] https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.writestr |
Notice this patch is only for 'aws cloudformation package', but the zipfile module is used in several other places, like lambda and codedeploy. If you consider the writestr approach is good enough, perhaps it is best to write a wrapper module for zipfile, to have something consistent. I can code the whole thing as soon as you agree on a solution. |
Does this have the effect that the mtime is set to the current time in the generated zip file if it was previously set to before 1980? |
dstufft@ that's right, it will only override the mtime for the file inside the zip, not the source file. |
There hasn't been any activity on this PR for a few years, and the initial maintainer response was against these changes. The original issue referenced (#2639) seems to suggest the problem was caused by timestamp issues introduced by a third-party library that have since been fixed. I think this PR should be closed but can be revisited if necessary. |
Related: #2639