[Git][reproducible-builds/diffoscope][master] Do not exit with a traceback if paths are inaccessible, either directly, via...

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue Jan 21 11:44:07 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
a5486ebd by Chris Lamb at 2025-01-21T11:43:40+00:00
Do not exit with a traceback if paths are inaccessible, either directly, via symbolic links or within a directory. (Closes: #367, Debian:#1065498)

- - - - -


4 changed files:

- diffoscope/comparators/utils/compare.py
- diffoscope/comparators/utils/container.py
- diffoscope/readers/__init__.py
- diffoscope/utils.py


Changes:

=====================================
diffoscope/comparators/utils/compare.py
=====================================
@@ -25,7 +25,7 @@ import subprocess
 
 from diffoscope.tools import tool_required
 from diffoscope.exc import RequiredToolNotFound
-from diffoscope.utils import exit_if_paths_do_not_exist
+from diffoscope.utils import exit_if_paths_inaccessible
 from diffoscope.config import Config
 from diffoscope.excludes import any_excluded
 from diffoscope.profiling import profile
@@ -55,7 +55,7 @@ def compare_root_paths(path1, path2):
     )
 
     if not Config().new_file:
-        exit_if_paths_do_not_exist(path1, path2)
+        exit_if_paths_inaccessible(path1, path2)
     if any_excluded(path1, path2):
         return None
 


=====================================
diffoscope/comparators/utils/container.py
=====================================
@@ -198,9 +198,13 @@ class Container(metaclass=abc.ABCMeta):
                 difference.add_comment(msg)
                 return difference
 
-            difference = compare_files(
-                file1, file2, source=None, diff_content_only=no_recurse
-            )
+            try:
+                difference = compare_files(
+                    file1, file2, source=None, diff_content_only=no_recurse
+                )
+            except PermissionError as exc:
+                logger.warning(f"Skipping {exc.filename} ({exc.strerror})")
+                return
 
             if isinstance(file1, AbstractMissingType) or isinstance(
                 file2, AbstractMissingType


=====================================
diffoscope/readers/__init__.py
=====================================
@@ -19,13 +19,13 @@
 
 import codecs
 
-from diffoscope.utils import exit_if_paths_do_not_exist
+from diffoscope.utils import exit_if_paths_inaccessible
 
 from .json import JSONReaderV1
 
 
 def load_diff_from_path(path):
-    exit_if_paths_do_not_exist(path)
+    exit_if_paths_inaccessible(path)
     with open(path, "rb") as fp:
         return load_diff(codecs.getreader("utf-8")(fp), path)
 


=====================================
diffoscope/utils.py
=====================================
@@ -58,16 +58,29 @@ def format_bytes(size, decimal_places=2):
     return f"{size:.{decimal_places}f} {unit}"
 
 
-def exit_if_paths_do_not_exist(*paths):
+def exit_if_paths_inaccessible(*paths):
+    """
+    Exit if the specified *paths are inaccessible, either by:
+
+        a) simply being missing
+        b) being a dangling symbolic links
+        c) being inaccessible (directly or via a symbolic link
+    """
+
     flag = False
     for path in paths:
-        if os.path.lexists(path):
-            continue
-        flag = True
-        print(
-            f"{sys.argv[0]}: {path}: No such file or directory",
-            file=sys.stderr,
-        )
+        if not os.path.lexists(path):
+            flag = True
+            print(
+                f"{sys.argv[0]}: {path}: No such file or directory",
+                file=sys.stderr,
+            )
+        elif not os.access(path, os.R_OK):
+            flag = True
+            print(
+                f"{sys.argv[0]}: {path}: Permission denied",
+                file=sys.stderr,
+            )
 
     if flag:
         sys.exit(2)



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

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/a5486ebd402108c4508613a8ebfbda12baa9b4c5
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/20250121/f32261bb/attachment.htm>


More information about the rb-commits mailing list