Loading diffoscope/comparators/utils/compare.py +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading diffoscope/comparators/utils/container.py +7 −3 Original line number Diff line number Diff line Loading @@ -198,9 +198,13 @@ class Container(metaclass=abc.ABCMeta): difference.add_comment(msg) return difference 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 Loading diffoscope/readers/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading diffoscope/utils.py +21 −8 Original line number Diff line number Diff line Loading @@ -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 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) Loading Loading
diffoscope/comparators/utils/compare.py +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading
diffoscope/comparators/utils/container.py +7 −3 Original line number Diff line number Diff line Loading @@ -198,9 +198,13 @@ class Container(metaclass=abc.ABCMeta): difference.add_comment(msg) return difference 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 Loading
diffoscope/readers/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading
diffoscope/utils.py +21 −8 Original line number Diff line number Diff line Loading @@ -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 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) Loading