Skip to content

Commit 0889423

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 4f373a4 commit 0889423

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
@@ -564,9 +564,14 @@ def diff_metal_helper(diff_from, diff_to):
564564

565565

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

571576
except Exception as e:
572577
print(f"Error in guestfs process for {image_path}: {e}", file=sys.stderr)
@@ -575,6 +580,13 @@ def diff_metal_helper(diff_from, diff_to):
575580
if g:
576581
g.close()
577582

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

0 commit comments

Comments
 (0)