BackupError->BackupWarning, BackupOSError->BackupOSWarning

This commit is contained in:
Thomas Waldmann 2023-11-15 18:41:02 +01:00
parent 900a1674df
commit e8fa4986cc
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
4 changed files with 28 additions and 17 deletions

View File

@ -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 <path>,
# 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))

View File

@ -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:

View File

@ -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

View File

@ -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):