[solved] Make "compare" command deterministic?
Posted: 2015-03-19T23:41:21-07:00
A weird one for you...
It looks like the compare command produces different results if the base file ctime changes between runs (ie. if the file is touched). That is, it produces a file with different bytes, the image signature itself doesn't change.
Is there any way to make compare produce deterministic output (ie. ignore filesystem metadata)? Caveats: I need file bytes to be the same, I cannot easily use the image signature for what I'm doing. Also, I can't just set ctime because it's actually the filesystem inode data modification time and cannot be changed easily: http://stackoverflow.com/q/4537291/128597.
Here's my "proof" of this behavior:
^ This can be repeated as many times, and will deterministically create the same diff_image.png.
But, merely touching the base image will change the resulting file:
Interestingly, touching the other_image.png does not affect the compare output.
It looks like the compare command produces different results if the base file ctime changes between runs (ie. if the file is touched). That is, it produces a file with different bytes, the image signature itself doesn't change.
Is there any way to make compare produce deterministic output (ie. ignore filesystem metadata)? Caveats: I need file bytes to be the same, I cannot easily use the image signature for what I'm doing. Also, I can't just set ctime because it's actually the filesystem inode data modification time and cannot be changed easily: http://stackoverflow.com/q/4537291/128597.
Here's my "proof" of this behavior:
Code: Select all
$ compare base_image.png other_image.png diff_image.png
$ md5 *
MD5 (base_image.png) = 8f50e3814de43750547facfc1c36851b
MD5 (other_image.png) = 448632ae88cb97de138f0cdc5ad1bba4
MD5 (diff_image.png) = ce5715a887fd1585688889f021b3a7b6
But, merely touching the base image will change the resulting file:
Code: Select all
$ touch base_image.png
$ compare base_image.png other_image.png diff_image.png
$ md5 *
MD5 (base_image.png) = 8f50e3814de43750547facfc1c36851b
MD5 (other_image.png) = 448632ae88cb97de138f0cdc5ad1bba4
MD5 (diff_image.png) = fc320022b8fbf1d3d390c3ca093a17e2