[diffoscope] 01/01: Show extended filesystem metadata (etc.) even when directly comparing two files, not just when we specify two directories. (Closes: #888402)

Chris Lamb chris at chris-lamb.co.uk
Thu Jan 25 23:37:47 CET 2018


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 59eb4bfd298f3fdb6f4f0d84780b53eb67703f52
Author: Chris Lamb <lamby at debian.org>
Date:   Thu Jan 25 23:03:18 2018 +1100

    Show extended filesystem metadata (etc.) even when directly comparing two files, not just when we specify two directories. (Closes: #888402)
---
 diffoscope/comparators/directory.py     |  4 ++++
 diffoscope/comparators/utils/compare.py | 13 +++++++++++--
 tests/data/archive12.diff.txt           | 11 +++++++++++
 tests/data/output.colored.txt           | 11 +++++++++++
 tests/data/output.json                  |  5 +++++
 tests/data/output.md                    | 13 +++++++++++++
 tests/data/output.rst                   | 17 +++++++++++++++++
 tests/data/output.txt                   | 11 +++++++++++
 tests/test_presenters.py                |  6 +++---
 9 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index 19a0d97..b939664 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -132,6 +132,10 @@ def compare_meta(path1, path2):
     logger.debug('compare_meta(%s, %s)', path1, path2)
     differences = []
 
+    # Don't run any commands if any of the paths do not exist
+    if not os.path.exists(path1) or not os.path.exists(path2):
+        return differences
+
     try:
         differences.append(Difference.from_command(Stat, path1, path2))
     except RequiredToolNotFound:
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index 66a03cd..beaf7ff 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -50,7 +50,8 @@ class Xxd(Command):
 
 
 def compare_root_paths(path1, path2):
-    from ..directory import FilesystemDirectory, FilesystemFile, compare_directories
+    from ..directory import FilesystemDirectory, FilesystemFile, \
+        compare_directories, compare_meta
 
     if not Config().new_file:
         bail_if_non_existing(path1, path2)
@@ -62,7 +63,15 @@ def compare_root_paths(path1, path2):
     file1 = specialize(FilesystemFile(path1, container=container1))
     container2 = FilesystemDirectory(os.path.dirname(path2)).as_container
     file2 = specialize(FilesystemFile(path2, container=container2))
-    return compare_files(file1, file2)
+    difference = compare_files(file1, file2)
+    meta = compare_meta(path1, path2)
+    if meta:
+        # Create an "empty" difference so we have something to attach file
+        # metadata to.
+        if difference is None:
+            difference = Difference(None, file1.name, file2.name)
+        difference.add_details(meta)
+    return difference
 
 
 def compare_files(file1, file2, source=None, diff_content_only=False):
diff --git a/tests/data/archive12.diff.txt b/tests/data/archive12.diff.txt
index 3b861ab..50a1ebe 100644
--- a/tests/data/archive12.diff.txt
+++ b/tests/data/archive12.diff.txt
@@ -13,3 +13,14 @@
 │ │ @@ -1 +1 @@
 │ │ -a
 │ │ +b
+├── stat {}
+│ @@ -1,8 +1,8 @@
+│  
+│    Size: 10240     	Blocks: 24         IO Block: 4096   regular file
+│  Links: 1
+│  Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)
+│  
+│ -Modify: 2017-06-18 07:22:17.232540259 +0000
+│ +Modify: 2017-06-18 07:22:17.196540208 +0000
+│  
+│   Birth: -
diff --git a/tests/data/output.colored.txt b/tests/data/output.colored.txt
index 62102c0..3205fc2 100644
--- a/tests/data/output.colored.txt
+++ b/tests/data/output.colored.txt
@@ -29,3 +29,14 @@
 │ @@ -1 +1 @@
 │ -destination: broken
 │ +destination: really-broken
+├── stat {}
+│ @@ -1,8 +1,8 @@
+│  
+│    Size: 10240     	Blocks: 24         IO Block: 4096   regular file
+│  Links: 1
+│  Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)
+│  
+│ -Modify: 2017-06-18 07:22:17.216540236 +0000
+│ +Modify: 2017-06-18 07:22:17.196540208 +0000
+│  
+│   Birth: -
diff --git a/tests/data/output.json b/tests/data/output.json
index d8b5eba..8a7caad 100644
--- a/tests/data/output.json
+++ b/tests/data/output.json
@@ -21,6 +21,11 @@
         "symlink"
       ],
       "unified_diff": "@@ -1 +1 @@\n-destination: broken\n+destination: really-broken\n"
+    },
+    {
+      "source1": "stat {}",
+      "source2": "stat {}",
+      "unified_diff": "@@ -1,8 +1,8 @@\n \n   Size: 10240     \tBlocks: 24         IO Block: 4096   regular file\n Links: 1\n Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)\n \n-Modify: 2017-06-18 07:22:17.216540236 +0000\n+Modify: 2017-06-18 07:22:17.196540208 +0000\n \n  Birth: -\n"
     }
   ]
 }
diff --git a/tests/data/output.md b/tests/data/output.md
index a147d58..31abb52 100644
--- a/tests/data/output.md
+++ b/tests/data/output.md
@@ -36,3 +36,16 @@ symlink
     -destination: broken
     +destination: really-broken
 
+## stat {}
+
+    @@ -1,8 +1,8 @@
+     
+       Size: 10240     	Blocks: 24         IO Block: 4096   regular file
+     Links: 1
+     Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)
+     
+    -Modify: 2017-06-18 07:22:17.216540236 +0000
+    +Modify: 2017-06-18 07:22:17.196540208 +0000
+     
+      Birth: -
+
diff --git a/tests/data/output.rst b/tests/data/output.rst
index 08e60e3..a08aa92 100644
--- a/tests/data/output.rst
+++ b/tests/data/output.rst
@@ -50,3 +50,20 @@ symlink
     -destination: broken
     +destination: really-broken
 
+-------
+stat {}
+-------
+
+::
+
+    @@ -1,8 +1,8 @@
+     
+       Size: 10240     	Blocks: 24         IO Block: 4096   regular file
+     Links: 1
+     Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)
+     
+    -Modify: 2017-06-18 07:22:17.216540236 +0000
+    +Modify: 2017-06-18 07:22:17.196540208 +0000
+     
+      Birth: -
+
diff --git a/tests/data/output.txt b/tests/data/output.txt
index 681ece0..7bfb953 100644
--- a/tests/data/output.txt
+++ b/tests/data/output.txt
@@ -29,3 +29,14 @@
 │ @@ -1 +1 @@
 │ -destination: broken
 │ +destination: really-broken
+├── stat {}
+│ @@ -1,8 +1,8 @@
+│  
+│    Size: 10240     	Blocks: 24         IO Block: 4096   regular file
+│  Links: 1
+│  Access: (0644/-rw-r--r--)  Uid: ( 1000/   lamby)   Gid: ( 1000/   lamby)
+│  
+│ -Modify: 2017-06-18 07:22:17.216540236 +0000
+│ +Modify: 2017-06-18 07:22:17.196540208 +0000
+│  
+│   Birth: -
diff --git a/tests/test_presenters.py b/tests/test_presenters.py
index 66561db..f5bd409 100644
--- a/tests/test_presenters.py
+++ b/tests/test_presenters.py
@@ -137,7 +137,7 @@ def test_html_option_with_file(tmpdir, capsys):
     assert out == ''
     with open(report_path, 'r', encoding='utf-8') as f:
         body = extract_body(f.read())
-        assert body.count('div class="difference"') == 4
+        assert body.count('div class="difference"') == 5
 
 
 @skip_unless_tools_exist('compare', 'convert', 'sng')
@@ -161,13 +161,13 @@ def test_htmldir_option(tmpdir, capsys):
     assert os.path.isdir(html_dir)
     with open(os.path.join(html_dir, 'index.html'), 'r', encoding='utf-8') as f:
         body = extract_body(f.read())
-        assert body.count('div class="difference"') == 4
+        assert body.count('div class="difference"') == 5
 
 
 def test_html_option_with_stdout(capsys):
     body = extract_body(run(capsys, '--html', '-'))
 
-    assert body.count('div class="difference"') == 4
+    assert body.count('div class="difference"') == 5
 
 
 def test_html_regression_875281(tmpdir, capsys):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list