Skip to content

Commit edf83ac

Browse files
committed
cmd-diff: attempt to normalize metal diffs
The diffs contain a bunch of files with sha256 checksums in them, which are unique on every build. Let's attempt to normalize the output directories so the diffs will me less noisy and more meaningful. Also fixup some permissions on some files because they can't be diffed otherwise.
1 parent daf754e commit edf83ac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/cmd-diff

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,14 @@ def diff_metal_helper(diff_from, diff_to):
561561
g.mount_ro(efi, "/boot/efi")
562562

563563
with tempfile.NamedTemporaryFile(suffix=".tar", delete=True) as tmp_tar:
564+
# Exclude ostree/repo/objects. It just adds noise to the diff
565+
excludes = ['*ostree/repo/objects/*']
564566
g.tar_out("/", tmp_tar.name, xattrs=True, selinux=True, excludes=excludes)
565-
# Extract the tarball.
566-
runcmd(['tar', '-xf', tmp_tar.name, '-C', diff_dir])
567+
# Extract the tarball. Normalize the output by replacing sha256sum hashes
568+
# in filenames with XXXXXXXXXXXXXXXX so that we can get a real diff between
569+
# two of the same files in different builds.
570+
runcmd(['tar', '-xf', tmp_tar.name, '-C', diff_dir,
571+
'--transform', 's|[[:xdigit:]]{64}|XXXXXXXXXXXXXXXX|gx'])
567572

568573
except Exception as e:
569574
print(f"Error in guestfs process for {image_path}: {e}", file=sys.stderr)
@@ -572,6 +577,13 @@ def diff_metal_helper(diff_from, diff_to):
572577
if g:
573578
g.close()
574579

580+
# Some files like /etc/shadow and sudo have no read permissions so let's
581+
# open it up so the difftool can access it.
582+
runcmd(['find', diff_dir, '-type', 'f', '-perm', '000',
583+
'-exec', 'chmod', '--verbose', '444', '{}', ';'])
584+
runcmd(['find', diff_dir, '-type', 'f', '-perm', '111',
585+
'-exec', 'chmod', '--verbose', '555', '{}', ';'])
586+
575587
# Allow the caller to operate on these values
576588
return diff_dir_from, diff_dir_to
577589

0 commit comments

Comments
 (0)