[Reproducible-builds] Create tar archive with deterministic file order

Reiner Herrmann reiner at reiner-h.de
Sat Feb 14 21:48:47 UTC 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Steven,

On 02/14/2015 09:44 PM, Steven Chamberlain wrote:
> What would be a preferred way to build a tar archive with deterministic
> file order?
> 
> Firstly let me point out that:
> 
> $ find foo/ -type f -print0 | sort -z | xargs -0 tar -cvf foo.tar
> 
> is risky as the list of filenames could overflow what xargs can supply
> to a single invocation of tar.  In that case it would invoke tar again
> and clobber the previous output.
[...]
> Finally I ended up with this:
> 
> $ find foo/ -type f -print0 > filelist
> $ tar -Jcvf foo.tar.xz -T filelist --null
> 
> Does that seem like the neatest way, or do you have better suggestions?

In the wiki [1] we currently have the following solution, which is similar to yours:
# find src -print0 | LC_ALL=C sort -z | tar --null -T - --no-recursion -cf archive.tar

Setting LC_ALL is required as there could be a different sorting order depending on the
locale.

Regards,
 Reiner

[1] https://wiki.debian.org/ReproducibleBuilds/FileOrderInTarballs

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJU38K/AAoJEMzwSSjbDuqn9JQQAJIiKGCMtkFxP3S0YHSfXACf
6DbWaNaJkQaGECby+lMr/4/JKEgLRqqCrS93/kjlaC1kOUAyBFBYWuarA9EMhseB
AQupv86bvzzbL3vKxXCtF5ORZjo/9peHnxXt5bTn5QyyJrJEVbs6VRztjhTHVGSA
2iQm28AqeB/UPmEVt5U3x5QxbZkpNmtARDPSdcaRitxlxT5wb3HSNNMleGO/dLHk
IfBpxJmNefx5FHG/FmD7okZFoYhC8cnes3eqr+tWgcONJ6pVBAg59kt6DmScRi6O
bfKF2I9diuf/3tmlULUART7KW5kb/h9tUV1l4umaUK7aFifO2wHQU9SKsDNvNtpd
kHwQFPy9lzKumTYIMLtILBvE8iDUkTQ/z1lBBVlz+ZwkQxE0dhSTQ6c5eb1u+kCg
ljR0D3Z+JCCGB1dVS8moXYQcY9Ijxtd4ib5DQSBz5azh2GvPykA3LGVD+Zl1gGp6
pEyM7opavgWq/xQnk78Uux5PUiKkv4BZ0SBny8xd9226TEeXbtbS2+VE6EE3R7EY
cae0pVytS4MQHKEo/iJ3vfAPntG6aBu9fj2uF+QNnEAlh3UO6G+vYZ0JMfqg4/sY
a55hysAktptFNSl2+YAVJe6gAAXWARHlV84BWwgCHBaxFa7Nz7h2qT3n4SvIv7eX
DiN8o4GcSwP/dLvRRIt1
=tY8p
-----END PGP SIGNATURE-----



More information about the Reproducible-builds mailing list