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

For ZIP we need a bit of juggling with timestamps #34

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Conversation

cstamas
Copy link
Collaborator

@cstamas cstamas commented Sep 9, 2024

ZIP timestamp is "local" while Java time is UTC. This makes ZIP archives in fact TZ dependant (where were they built). This PR makes this gone, and normalized ZIPs will have timestamps set irrelevant of TZ where JVM building ZIP runs.

Example to test (in this PR branch):

$ git checkout issue-33
$ mvn clean install
[...]
$ unzip -lv target/archives/create-archive-time-0.zip
Archive:  target/archives/create-archive-time-0.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/0/
       1  Defl:N        3 -200% 01-01-1980 08:00 f4dbdf21  archive-time-0/0/0.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/1/
       1  Defl:N        3 -200% 01-01-1980 08:00 83dcefb7  archive-time-0/1/1.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/2/
       1  Defl:N        3 -200% 01-01-1980 08:00 1ad5be0d  archive-time-0/2/2.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/3/
       1  Defl:N        3 -200% 01-01-1980 08:00 6dd28e9b  archive-time-0/3/3.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/4/
       1  Defl:N        3 -200% 01-01-1980 08:00 f3b61b38  archive-time-0/4/4.txt
       9  Defl:N       11 -22% 01-01-1980 08:00 297b6afc  archive-time-0/4/Foo.class
--------          -------  ---                            -------
      14               38 -171%                            12 files
$ 
$ mvn clean install -Duser.timezone='America/Sao_Paolo'
[...]
$ unzip -lv target/archives/create-archive-time-0.zip
Archive:  target/archives/create-archive-time-0.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/0/
       1  Defl:N        3 -200% 01-01-1980 08:00 f4dbdf21  archive-time-0/0/0.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/1/
       1  Defl:N        3 -200% 01-01-1980 08:00 83dcefb7  archive-time-0/1/1.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/2/
       1  Defl:N        3 -200% 01-01-1980 08:00 1ad5be0d  archive-time-0/2/2.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/3/
       1  Defl:N        3 -200% 01-01-1980 08:00 6dd28e9b  archive-time-0/3/3.txt
       0  Defl:N        2   0% 01-01-1980 08:00 00000000  archive-time-0/4/
       1  Defl:N        3 -200% 01-01-1980 08:00 f3b61b38  archive-time-0/4/4.txt
       9  Defl:N       11 -22% 01-01-1980 08:00 297b6afc  archive-time-0/4/Foo.class
--------          -------  ---                            -------
      14               38 -171%                            12 files

Note: the timestamps in case of two Maven builds (w/ different TZ) are same. On master on other hand:

$ git checkout master
$ mvn clean install
[...]
$ unzip -lv target/archives/create-archive-time-0.zip
Archive:  target/archives/create-archive-time-0.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/0/
       1  Defl:N        3 -200% 01-01-1980 09:00 f4dbdf21  archive-time-0/0/0.txt
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/1/
       1  Defl:N        3 -200% 01-01-1980 09:00 83dcefb7  archive-time-0/1/1.txt
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/2/
       1  Defl:N        3 -200% 01-01-1980 09:00 1ad5be0d  archive-time-0/2/2.txt
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/3/
       1  Defl:N        3 -200% 01-01-1980 09:00 6dd28e9b  archive-time-0/3/3.txt
       0  Defl:N        2   0% 01-01-1980 09:00 00000000  archive-time-0/4/
       1  Defl:N        3 -200% 01-01-1980 09:00 f3b61b38  archive-time-0/4/4.txt
       9  Defl:N       11 -22% 01-01-1980 09:00 297b6afc  archive-time-0/4/Foo.class
--------          -------  ---                            -------
      14               38 -171%                            12 files
$ 
$ mvn clean install -Duser.timezone='America/Sao_Paolo'
[...]
$ unzip -lv target/archives/create-archive-time-0.zip
Archive:  target/archives/create-archive-time-0.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/0/
       1  Defl:N        3 -200% 01-01-1980 10:00 f4dbdf21  archive-time-0/0/0.txt
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/1/
       1  Defl:N        3 -200% 01-01-1980 10:00 83dcefb7  archive-time-0/1/1.txt
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/2/
       1  Defl:N        3 -200% 01-01-1980 10:00 1ad5be0d  archive-time-0/2/2.txt
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/3/
       1  Defl:N        3 -200% 01-01-1980 10:00 6dd28e9b  archive-time-0/3/3.txt
       0  Defl:N        2   0% 01-01-1980 10:00 00000000  archive-time-0/4/
       1  Defl:N        3 -200% 01-01-1980 10:00 f3b61b38  archive-time-0/4/4.txt
       9  Defl:N       11 -22% 01-01-1980 10:00 297b6afc  archive-time-0/4/Foo.class
--------          -------  ---                            -------
      14               38 -171%                            12 files

Fixes #33

ZIP timestamp is "local" while Java time is UTC.
This makes ZIP archives in fact TZ dependant (where
were they built). This PR makes this gone, and
normalized ZIPs will have timestamps set irrelevant
of TZ where JVM building ZIP runs.

Fixes #33
@cstamas cstamas self-assigned this Sep 9, 2024
@cstamas cstamas changed the title For ZIP we need a bit of juggling with timestamps as For ZIP we need a bit of juggling with timestamps Sep 9, 2024
@cstamas cstamas merged commit 74f184f into master Sep 9, 2024
3 checks passed
@cstamas cstamas deleted the issue-33 branch September 9, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Normalized ZIP archives are reproducible only within same TZ
1 participant