1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 17:57:59 +00:00

Merge pull request #3727 from milkey-mouse/issue-3448-bp1.1

set rc=1 when extracting damaged files (1.1 backport)
This commit is contained in:
TW 2018-03-25 20:47:50 +02:00 committed by GitHub
commit b6fd9ba6a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View file

@ -127,6 +127,12 @@ def is_special(mode):
return stat.S_ISBLK(mode) or stat.S_ISCHR(mode) or stat.S_ISFIFO(mode)
class BackupError(Exception):
"""
Exception raised for non-OSError-based exceptions while accessing backup files.
"""
class BackupOSError(Exception):
"""
Wrapper for OSError raised while accessing backup files.
@ -551,11 +557,10 @@ def extract_item(self, item, restore_attrs=True, dry_run=False, stdout=False, sp
if 'size' in item:
item_size = item.size
if item_size != item_chunks_size:
logger.warning('{}: size inconsistency detected: size {}, chunks size {}'.format(
item.path, item_size, item_chunks_size))
raise BackupError('Size inconsistency detected: size {}, chunks size {}'.format(
item_size, item_chunks_size))
if has_damaged_chunks:
logger.warning('File %s has damaged (all-zero) chunks. Try running borg check --repair.' %
remove_surrogates(item.path))
raise BackupError('File has damaged (all-zero) chunks. Try running borg check --repair.')
return
original_path = original_path or item.path
@ -611,11 +616,10 @@ def make_parent(path):
if 'size' in item:
item_size = item.size
if item_size != item_chunks_size:
logger.warning('{}: size inconsistency detected: size {}, chunks size {}'.format(
item.path, item_size, item_chunks_size))
raise BackupError('Size inconsistency detected: size {}, chunks size {}'.format(
item_size, item_chunks_size))
if has_damaged_chunks:
logger.warning('File %s has damaged (all-zero) chunks. Try running borg check --repair.' %
remove_surrogates(item.path))
raise BackupError('File has damaged (all-zero) chunks. Try running borg check --repair.')
return
with backup_io:
# No repository access beyond this point.

View file

@ -37,7 +37,7 @@
from . import shellpattern
from .algorithms.checksums import crc32
from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
from .archive import BackupOSError, backup_io
from .archive import BackupError, BackupOSError, backup_io
from .cache import Cache, assert_secure, SecurityManager
from .constants import * # NOQA
from .compress import CompressionSpec
@ -750,7 +750,7 @@ def peek_and_store_hardlink_masters(item, matched):
else:
archive.extract_item(item, stdout=stdout, sparse=sparse, hardlink_masters=hardlink_masters,
stripped_components=strip_components, original_path=orig_path, pi=pi)
except BackupOSError as e:
except (BackupOSError, BackupError) as e:
self.print_warning('%s: %s', remove_surrogates(orig_path), e)
if pi: