Can't produce byte-to-byte equivalent tar archives on MacOS #930
-
I'd like to produce byte-to-byte equivalent tar archives if the packaged file's content is the same. See https://www.gnu.org/software/tar/manual/html_chapter/tar_8.html#SEC147
The default behavior was changed in 1.33, to omit the PID of the tar process by default: I used the following test case:
I tested with the bottled artifacts of the gnu-tar Formula in versions 1.32, 1.33, 1.34 on Big Sur and they all produce a diff, i.e. although the packaged file's content is the same, the resulting tar file is not byte-to-byte equivalent. I experimented with several combinations of the options, but all of them produced a diff. I also tested with an alpine container, with gnu tar 1.33, and there the configured pax header works as expected and I get byte-to-byte equivalent outputs:
So I conclude that it is somehow related to the bottled artifacts, but I couldn't figure it out. I didn't attempt to build the binaries from source. This golang issue had the same motivation as I have for this issue: golang/go#12358 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
This is likely due to the filesystem and not Homebrew. AFPS does not guarantee a sorted order when you glob files in your example. |
Beta Was this translation helpful? Give feedback.
-
Your test case is invalid, because you're telling GNU tar to gzip the tarballs, and the gzip file format contains a 4-byte timestamp right where your diff indicates a numerical difference of 1. Since you sleep for 1 second between generating the tarballs, the diff is completely accounted for. Remove the |
Beta Was this translation helpful? Give feedback.
-
When @gromgit mentioned the alternative approach to use bzip2 instead of gzip, with |
Beta Was this translation helpful? Give feedback.
When
tar
is executed with thez
option, it filters the archive throughgzip
. On my system, the Apple version of gzip was installed and after installing the GNU version withbrew install gzip
, my test case worked as expected.@gromgit mentioned the alternative approach to use bzip2 instead of gzip, with
j
.