[Git][reproducible-builds/diffoscope][master] Fix diffing CBFS names containing spaces

Chris Lamb (@lamby) gitlab at salsa.debian.org
Mon Jan 31 18:02:57 UTC 2022



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
5269c1c0 by Alyssa Ross at 2022-01-31T17:49:04+00:00
Fix diffing CBFS names containing spaces

The first entry in my coreboot.rom is called "cbfs master header", so
the previous behaviour of splitting on whitespace would try to extract
a non-existent file named "cbfs".

The -k argument to cbfstool print tells it to use "machine-readable"
output, which means fields are separated with tabs.  I don't think
there's any way to handle a name that actually contains a tab
character (we can't assume name is the nth last field because the
number of fields is variable), so we just have to hope that doesn't
come up.

- - - - -


2 changed files:

- diffoscope/comparators/cbfs.py
- tests/comparators/test_cbfs.py


Changes:

=====================================
diffoscope/comparators/cbfs.py
=====================================
@@ -52,7 +52,7 @@ class CbfsListing(Command):
 class CbfsContainer(Archive):
     @tool_required("cbfstool")
     def entries(self, path):
-        cmd = ["cbfstool", path, "print"]
+        cmd = ["cbfstool", path, "print", "-k"]
         output = our_check_output(cmd).decode("utf-8")
         header = True
         for line in output.rstrip("\n").split("\n"):
@@ -60,7 +60,7 @@ class CbfsContainer(Archive):
                 if line.startswith("Name"):
                     header = False
                 continue
-            name = line.split()[0]
+            name = line.split("\t", 1)[0]
             if name == "(empty)":
                 continue
             yield name


=====================================
tests/comparators/test_cbfs.py
=====================================
@@ -51,7 +51,7 @@ def rom1(tmpdir):
             "-f",
             TEST_FILE1_PATH,
             "-n",
-            "text",
+            "test file",
             "-t",
             "raw",
         ),
@@ -77,7 +77,7 @@ def rom2(tmpdir):
             "-f",
             TEST_FILE2_PATH,
             "-n",
-            "text",
+            "test file",
             "-t",
             "raw",
         ),
@@ -128,13 +128,13 @@ def test_listing(differences):
     # and the git log of this file), perform only these basic coherence check.
 
     assert differences[0].source1.startswith("cbfstool")
-    assert re.search(r"\+text\s.*\sraw\s", differences[0].unified_diff)
+    assert re.search(r"\+test file\s.*\sraw\s", differences[0].unified_diff)
 
 
 @skip_unless_tools_exist("cbfstool")
 def test_content(differences):
-    assert differences[1].source1 == "text"
-    assert differences[1].source2 == "text"
+    assert differences[1].source1 == "test file"
+    assert differences[1].source2 == "test file"
     expected_diff = get_data("text_ascii_expected_diff")
     assert differences[1].unified_diff == expected_diff
 



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/5269c1c0ed8ed29eeb609ac979a6aabeb1743916

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/5269c1c0ed8ed29eeb609ac979a6aabeb1743916
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/20220131/71a03976/attachment.htm>


More information about the rb-commits mailing list