[Git][reproducible-builds/diffoscope][master] 2 commits: tests: add test case of identical files different mtimes

Chris Lamb (@lamby) gitlab at salsa.debian.org
Fri Jun 27 17:27:08 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
0c2b31a4 by Alex at 2025-06-27T16:22:31+02:00
tests: add test case of identical files different mtimes

When run with "exclude-directory-metadata=no" we expect diffoscope to pick
up a diff between two byte-by-byte identical files with differing metadata.

Related to reproducible-builds/diffoscope#411

Co-authored-by: kryggird <43894260+kryggird at users.noreply.github.com>
Co-authored-by: Max Albrecht <1 at 178.is>
Co-authored-by: Joel Cantillo <joel.cantillo at proton.me>

- - - - -
c8426f05 by Alex at 2025-06-27T16:23:10+02:00
fix(comparators/utils/compare): do not return early after checking only content

Commit 5b187ad563526412fb5a5b328464f13047a49eff introduces a regression by
unconditionally returning too early when files are identical contentwise. A
configured check for diffs in metadata would be skipped.

Instead of returning early, we bypass the specialize() call in compare_files
for binary identical files through an if-else, such that metadata checks can
still be run if required.

Closes reproducible-builds/diffoscope#411

Co-authored-by: kryggird <43894260+kryggird at users.noreply.github.com>
Co-authored-by: Max Albrecht <1 at 178.is>
Co-authored-by: Joel Cantillo <joel.cantillo at proton.me>

- - - - -


2 changed files:

- diffoscope/comparators/utils/compare.py
- tests/comparators/test_directory.py


Changes:

=====================================
diffoscope/comparators/utils/compare.py
=====================================
@@ -68,10 +68,12 @@ def compare_root_paths(path1, path2):
     file2 = FilesystemFile(path2, container=container2)
 
     with profile("has_same_content_as", file1):
-        if file1.has_same_content_as(file2):
-            return None
+        is_binary_identical = file1.has_same_content_as(file2)
 
-    difference = compare_files(file1, file2)
+    if is_binary_identical:
+        difference = None
+    else:
+        difference = compare_files(file1, file2)
 
     if Config().exclude_directory_metadata in ("no", "recursive"):
         meta = compare_meta(path1, path2)


=====================================
tests/comparators/test_directory.py
=====================================
@@ -19,12 +19,15 @@
 
 import os
 import shutil
+import time
+
 import pytest
 
 from diffoscope.comparators.binary import FilesystemFile
 from diffoscope.comparators.directory import compare_directories
 from diffoscope.comparators.utils.compare import compare_root_paths
 from diffoscope.comparators.utils.specialize import specialize
+from diffoscope.config import Config
 
 from ..utils.data import data, get_data, assert_diff
 
@@ -125,3 +128,20 @@ def test_compare_both_ways(tmpdir):
 
     assert_diff(compare_root_paths(a, b), "test_directory_a_b_diff")
     assert_diff(compare_root_paths(b, a), "test_directory_b_a_diff")
+
+
+def test_identical_files_different_mtime(monkeypatch, tmpdir):
+
+    monkeypatch.setattr(Config(), "exclude_directory_metadata", "no")
+
+    file1_path = str(tmpdir.join("file1"))
+    file2_path = str(tmpdir.join("file2"))
+
+    now = time.time()
+    for path, t in ((file1_path, now - 3600), (file2_path, now)):
+        with open(path, "w") as f:
+            f.write("identical content")
+        os.utime(path, (t, t))
+
+    difference = compare_root_paths(file1_path, file2_path)
+    assert difference is not None



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/7c30c975ad18b6fe1277c350c82a399290e4c9bc...c8426f059473723d55f08858d232dc152b8c5382

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/7c30c975ad18b6fe1277c350c82a399290e4c9bc...c8426f059473723d55f08858d232dc152b8c5382
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20250627/d7c4985f/attachment.htm>


More information about the rb-commits mailing list