Commit 59eb4bfd authored by Chris Lamb's avatar Chris Lamb 💬

Show extended filesystem metadata (etc.) even when directly comparing two...

Show extended filesystem metadata (etc.) even when directly comparing two files, not just when we specify two directories. (Closes: #888402)
parent 26d8a66b
......@@ -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:
......
......@@ -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):
......
......@@ -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: -
......@@ -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: -
......@@ -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"
}
]
}
......@@ -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: -
......@@ -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: -
......@@ -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: -
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment