From e8fa4986cc0688b036cbb8d7f4f6498b998f9782 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 15 Nov 2023 18:41:02 +0100 Subject: [PATCH] BackupError->BackupWarning, BackupOSError->BackupOSWarning --- src/borg/archiver/create_cmd.py | 22 ++++++++++++++-------- src/borg/archiver/extract_cmd.py | 13 +++++++------ src/borg/helpers/__init__.py | 2 +- src/borg/helpers/errors.py | 8 ++++++-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/borg/archiver/create_cmd.py b/src/borg/archiver/create_cmd.py index 4ab25575..0dfaee95 100644 --- a/src/borg/archiver/create_cmd.py +++ b/src/borg/archiver/create_cmd.py @@ -29,7 +29,7 @@ from ..helpers import prepare_subprocess_env from ..helpers import sig_int, ignore_sigint from ..helpers import iter_separated from ..helpers import MakePathSafeAction -from ..helpers import Error, CommandError, BackupExcWarning, FileChangedWarning +from ..helpers import Error, CommandError, BackupWarning, BackupOSWarning, FileChangedWarning from ..manifest import Manifest from ..patterns import PatternMatcher from ..platform import is_win32 @@ -121,8 +121,11 @@ class CreateMixIn: read_special=args.read_special, dry_run=dry_run, ) - except (BackupOSError, BackupError) as e: - self.print_warning_instance(BackupExcWarning(path, e)) + except BackupOSError as e: + self.print_warning_instance(BackupOSWarning(path, e)) + status = "E" + except BackupError as e: + self.print_warning_instance(BackupWarning(path, e)) status = "E" if status == "C": self.print_warning_instance(FileChangedWarning(path)) @@ -149,7 +152,7 @@ class CreateMixIn: path=path, cache=cache, fd=sys.stdin.buffer, mode=mode, user=user, group=group ) except BackupOSError as e: - self.print_warning_instance(BackupExcWarning(path, e)) + self.print_warning_instance(BackupOSWarning(path, e)) status = "E" else: status = "+" # included @@ -180,9 +183,9 @@ class CreateMixIn: # if we get back here, we've finished recursing into , # we do not ever want to get back in there (even if path is given twice as recursion root) skip_inodes.add((st.st_ino, st.st_dev)) - except (BackupOSError, BackupError) as e: + except BackupOSError as e: # this comes from os.stat, self._rec_walk has own exception handler - self.print_warning_instance(BackupExcWarning(path, e)) + self.print_warning_instance(BackupOSWarning(path, e)) continue if not dry_run: if args.progress: @@ -521,8 +524,11 @@ class CreateMixIn: dry_run=dry_run, ) - except (BackupOSError, BackupError) as e: - self.print_warning_instance(BackupExcWarning(path, e)) + except BackupOSError as e: + self.print_warning_instance(BackupOSWarning(path, e)) + status = "E" + except BackupError as e: + self.print_warning_instance(BackupWarning(path, e)) status = "E" if status == "C": self.print_warning_instance(FileChangedWarning(path)) diff --git a/src/borg/archiver/extract_cmd.py b/src/borg/archiver/extract_cmd.py index 1dc7322e..5732f2bf 100644 --- a/src/borg/archiver/extract_cmd.py +++ b/src/borg/archiver/extract_cmd.py @@ -12,7 +12,7 @@ from ..helpers import archivename_validator, PathSpec from ..helpers import remove_surrogates from ..helpers import HardLinkManager from ..helpers import ProgressIndicatorPercent -from ..helpers import BackupExcWarning, IncludePatternNeverMatchedWarning +from ..helpers import BackupWarning, BackupOSWarning, IncludePatternNeverMatchedWarning from ..manifest import Manifest from ..logger import create_logger @@ -66,7 +66,7 @@ class ExtractMixIn: try: archive.extract_item(dir_item, stdout=stdout) except BackupOSError as e: - self.print_warning_instance(BackupExcWarning(remove_surrogates(dir_item.path), e)) + self.print_warning_instance(BackupOSWarning(remove_surrogates(dir_item.path), e)) if output_list: logging.getLogger("borg.output.list").info(remove_surrogates(item.path)) try: @@ -80,9 +80,10 @@ class ExtractMixIn: archive.extract_item( item, stdout=stdout, sparse=sparse, hlm=hlm, pi=pi, continue_extraction=continue_extraction ) - except (BackupOSError, BackupError) as e: - self.print_warning_instance(BackupExcWarning(remove_surrogates(orig_path), e)) - + except BackupOSError as e: + self.print_warning_instance(BackupOSWarning(remove_surrogates(orig_path), e)) + except BackupError as e: + self.print_warning_instance(BackupWarning(remove_surrogates(orig_path), e)) if pi: pi.finish() @@ -96,7 +97,7 @@ class ExtractMixIn: try: archive.extract_item(dir_item, stdout=stdout) except BackupOSError as e: - self.print_warning_instance(BackupExcWarning(remove_surrogates(dir_item.path), e)) + self.print_warning_instance(BackupOSWarning(remove_surrogates(dir_item.path), e)) for pattern in matcher.get_unmatched_include_patterns(): self.print_warning_instance(IncludePatternNeverMatchedWarning(pattern)) if pi: diff --git a/src/borg/helpers/__init__.py b/src/borg/helpers/__init__.py index d898fe09..ef8c9f97 100644 --- a/src/borg/helpers/__init__.py +++ b/src/borg/helpers/__init__.py @@ -13,7 +13,7 @@ from .checks import check_extension_modules, check_python from .datastruct import StableDict, Buffer, EfficientCollectionQueue from .errors import Error, ErrorWithTraceback, IntegrityError, DecompressionError, CancelledByUser, CommandError from .errors import RTError, modern_ec -from .errors import BorgWarning, FileChangedWarning, BackupExcWarning, IncludePatternNeverMatchedWarning +from .errors import BorgWarning, FileChangedWarning, BackupWarning, BackupOSWarning, IncludePatternNeverMatchedWarning from .errors import BackupError, BackupOSError, BackupRaceConditionError from .fs import ensure_dir, join_base_dir, get_socket_filename from .fs import get_security_dir, get_keys_dir, get_base_dir, get_cache_dir, get_config_dir, get_runtime_dir diff --git a/src/borg/helpers/errors.py b/src/borg/helpers/errors.py index 24917a0a..0aca4729 100644 --- a/src/borg/helpers/errors.py +++ b/src/borg/helpers/errors.py @@ -108,12 +108,16 @@ class IncludePatternNeverMatchedWarning(BorgWarning): exit_mcode = 101 -class BackupExcWarning(BorgWarning): +class BackupWarning(BorgWarning): """{}: {}""" exit_mcode = 102 - # TODO: override exit_code and compute the exit code based on the wrapped exception. + +class BackupOSWarning(BorgWarning): + """{}: {}""" + + exit_mcode = 104 class BackupError(Exception):