I need to archive some files deterministically, so that I get the same archive file if the content of the files is the same. I need this for testing for equality of the archive files later.
however, tar includes the timestamp information, and so I get different archive files even if the content of the files is the same.
how can I create an archive (with tar, zip or something else) that does not include timestamp information?
Note: I am aware that even if the two tar files differ, I can ignore their timestamps and compare only their content with tools such as tar --diff
or tarsum
. However, I am not allowed to use any other external tool for comparison (because of my setup); I just can test the two archive files for exact equality.
Note: I am aware that I could set the timestamp of all files to a given value before archiving the files, so their timestamps would be the same. However there are a lot of files, and I do not want to do this. I just want to archive these files without timestamp information
example:
$ mkdir copy1
$ touch copy1/file1
$ touch copy1/file2
$ sleep 60
$ mkdir copy2
$ touch copy2/file1
$ touch copy2/file2
$ ls -l copy1
total 0
-rw-r--r-- 1 david wheel 0 Oct 27 00:59 file1
-rw-r--r-- 1 david wheel 0 Oct 27 00:59 file2
$ ls -l copy2
total 0
-rw-r--r-- 1 david wheel 0 Oct 27 01:00 file1
-rw-r--r-- 1 david wheel 0 Oct 27 01:00 file2
# the content of those files is the same; they only differ by the their timestamp
$ (cd copy1; tar -cvf ../copy1.tar .)
$ (cd copy2; tar -cvf ../copy2.tar .)
$ tar -tvf copy1.tar
drwxr-xr-x 0 david wheel 0 Oct 27 00:59 ./
-rw-r--r-- 0 david wheel 0 Oct 27 00:59 ./file1
-rw-r--r-- 0 david wheel 0 Oct 27 00:59 ./file2
$ tar -tvf copy2.tar
drwxr-xr-x 0 david wheel 0 Oct 27 01:00 ./
-rw-r--r-- 0 david wheel 0 Oct 27 01:00 ./file1
-rw-r--r-- 0 david wheel 0 Oct 27 01:00 ./file2
$ diff copy1.tar copy2.tar
Binary files copy1.tar and copy2.tar differ
I tried with zip -X
instead of tar
, but I get the same result