1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-04 18:48:43 +00:00

Merge pull request #3568 from ThomasWaldmann/files-cache-exception-handling

files cache: improve exception handling, fixes #3553
This commit is contained in:
TW 2018-01-21 12:14:11 +01:00 committed by GitHub
commit e6539abc63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 26 deletions

View file

@ -502,7 +502,8 @@ class LocalCache(CacheStatsMixin):
self.files = {} self.files = {}
self._newest_cmtime = None self._newest_cmtime = None
logger.debug('Reading files cache ...') logger.debug('Reading files cache ...')
msg = None
try:
with IntegrityCheckedFile(path=os.path.join(self.path, 'files'), write=False, with IntegrityCheckedFile(path=os.path.join(self.path, 'files'), write=False,
integrity_data=self.cache_config.integrity.get('files')) as fd: integrity_data=self.cache_config.integrity.get('files')) as fd:
u = msgpack.Unpacker(use_list=True) u = msgpack.Unpacker(use_list=True)
@ -517,10 +518,16 @@ class LocalCache(CacheStatsMixin):
# in the end, this takes about 240 Bytes per file # in the end, this takes about 240 Bytes per file
self.files[path_hash] = msgpack.packb(entry._replace(age=entry.age + 1)) self.files[path_hash] = msgpack.packb(entry._replace(age=entry.age + 1))
except (TypeError, ValueError) as exc: except (TypeError, ValueError) as exc:
logger.warning('The files cache seems corrupt, ignoring it. ' msg = "The files cache seems invalid. [%s]" % str(exc)
'Expect lower performance. [%s]' % str(exc)) break
except OSError as exc:
msg = "The files cache can't be read. [%s]" % str(exc)
except FileIntegrityError as fie:
msg = "The files cache is corrupted. [%s]" % str(fie)
if msg is not None:
logger.warning(msg)
logger.warning('Continuing without files cache - expect lower performance.')
self.files = {} self.files = {}
return
def begin_txn(self): def begin_txn(self):
# Initialize transaction snapshot # Initialize transaction snapshot

View file

@ -3325,13 +3325,9 @@ class ArchiverCorruptionTestCase(ArchiverTestCaseBase):
def test_cache_files(self): def test_cache_files(self):
self.cmd('create', self.repository_location + '::test', 'input') self.cmd('create', self.repository_location + '::test', 'input')
self.corrupt(os.path.join(self.cache_path, 'files')) self.corrupt(os.path.join(self.cache_path, 'files'))
out = self.cmd('create', self.repository_location + '::test1', 'input')
if self.FORK_DEFAULT: # borg warns about the corrupt files cache, but then continues without files cache.
out = self.cmd('create', self.repository_location + '::test1', 'input', exit_code=2) assert 'files cache is corrupted' in out
assert 'failed integrity check' in out
else:
with pytest.raises(FileIntegrityError):
self.cmd('create', self.repository_location + '::test1', 'input')
def test_chunks_archive(self): def test_chunks_archive(self):
self.cmd('create', self.repository_location + '::test1', 'input') self.cmd('create', self.repository_location + '::test1', 'input')