From 237b3cb5ce61562e55fdac015aa2da8a10dd8a1d Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 17 Oct 2025 16:09:51 +0100 Subject: [PATCH] testers.testEqualContents: add checkMetadata option Allows ignoring file metadata differences (permissions, ownership) when comparing files. This is especially useful on darwin, where we often run into subtle issues like: -Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ wheel) +Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 350/ nixbld) --- doc/build-helpers/testers.chapter.md | 5 +++++ pkgs/build-support/testers/default.nix | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/build-helpers/testers.chapter.md b/doc/build-helpers/testers.chapter.md index e4e8ddbb2c17..49407c6e9b8e 100644 --- a/doc/build-helpers/testers.chapter.md +++ b/doc/build-helpers/testers.chapter.md @@ -421,6 +421,11 @@ Check that two paths have the same contents. : A message that is printed last if the file system object contents at the two paths don't match exactly. +`checkMetadata` (boolean) + +: Whether to fail on metadata differences, such as permissions or ownership. + Defaults to `true`. + :::{.example #ex-testEqualContents-toyexample} # Check that two paths have the same contents diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index c35e03cada76..ac31c22ab4a2 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -57,6 +57,7 @@ actual, expected, postFailureMessage ? null, + checkMetadata ? true, }: runCommand "equal-contents-${lib.strings.toLower assertion}" { @@ -66,12 +67,13 @@ expected postFailureMessage ; + excludeMetadata = if checkMetadata then "no" else "yes"; nativeBuildInputs = [ diffoscopeMinimal ]; } '' echo "Checking:" printf '%s\n' "$assertion" - if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata=no -- "$actual" "$expected" + if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata="$excludeMetadata" -- "$actual" "$expected" then echo echo 'Contents must be equal, but were not!'