tar软件包的完全相同的内容具有不同的校验和 [英] tar package has different checksum for exactly the same content

查看:334
本文介绍了tar软件包的完全相同的内容具有不同的校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GNU tar 1.30在SUSE Linux Enterprise Server 12 SP3系统上打包文件夹时,尽管文件内容不变,但总会提供不同的md5校验和。

Packaging a folder on a SUSE Linux Enterprise Server 12 SP3 system using GNU tar 1.30 always gives different md5 checksums although the file contents do not change.

我运行tar打包包含简单文本文件的文件夹:

I run tar to package my folder that contains a simple text file:

tar cf package.tar folder

尽管内容完全相同,但结果tar始终具有不同的md5(或sha1)校验和:

Nevertheless, although the content is exactly the same, the resulting tar always has a different md5 (or sha1) checksum:

$> rm -rf package.tar && tar cf package.tar folder && md5sum package.tar
e6383218596fffe118758b46e0edad1d  package.tar
$> rm -rf package.tar && tar cf package.tar folder && md5sum package.tar
1c5aa972e5bfa2ec78e63a9b3116e027  package.tar

因为linux文件系统似乎可以传送文件按照对tar的随机顺序,我尝试使用-sort 选项。但是结果命令对我来说不会改变校验和的问题。 tar的-mtime 选项在这里也无济于事,因为创建日期完全相同。

Because the linux file system seems to deliver files in a random order to tar, I tried using the --sort option. But the resulting command doesn't change the checksum issue for me. Also tar's --mtime option does not help here, since the creation dates are exactly the same.

推荐答案

您提供的档案文件包含 pax扩展标头
快速浏览一下它们的结构,发现它们在以下两个字段中有所不同:

The archives you provided contain pax extended headers. A quick glance at their structure reveals that they differ in these two fields:


  1. pax进程的进程ID(如

  2. 扩展头中的时间(访问时间)。
  3. $ us $头块中扩展头的名称的一部分,因此,此ustar头块的校验和也是如此。 >
  1. The process ID of the pax process (as part of a name for the extended header in the ustar header block, and consequently the checksum for this ustar header block).
  2. The atime (access time) in the extended header.

可用于创建可复制档案的一种解决方法是强制使用旧的unix ustar格式(而不是pax / posix格式):

One of the workarounds you can use for reproducible archive creation is to enforce the old unix ustar format (rather than the pax/posix format):

tar --format=ustar -cf package.tar folder

另一种选择是手动设置扩展名并删除atime,同时保留pax格式:

The other choice is to manually set the extended name and delete the atime while preserving the pax format:

tar --format=pax --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime -cf package.tar folder

现在两个存档的 md5sum 应该相同。

Now the md5sum should be the same for both archives.

这篇关于tar软件包的完全相同的内容具有不同的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆