check: handle repo w/o objects gracefully

normal check would complete, --repair would crash when trying
to write the rebuilt (empty) manifest out, since self.key was None
This commit is contained in:
Marian Beermann 2016-11-13 11:45:35 +01:00
parent 64a3fa8e73
commit 2261709e78
No known key found for this signature in database
GPG Key ID: 9B8450B91D1362C1
2 changed files with 10 additions and 0 deletions

View File

@ -833,6 +833,9 @@ class ArchiveChecker:
self.repair = repair
self.repository = repository
self.init_chunks()
if not self.chunks:
logger.error('Repository contains no apparent data at all, cannot continue check/repair.')
return False
self.key = self.identify_key(repository)
if Manifest.MANIFEST_ID not in self.chunks:
logger.error("Repository manifest not found!")

View File

@ -1444,6 +1444,13 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
self.cmd('check', self.repository_location, exit_code=0)
self.cmd('extract', '--dry-run', self.repository_location + '::archive1', exit_code=0)
def test_empty_repository(self):
with Repository(self.repository_location, exclusive=True) as repository:
for id_ in repository.list():
repository.delete(id_)
repository.commit()
self.cmd('check', self.repository_location, exit_code=1)
@pytest.mark.skipif(sys.platform == 'cygwin', reason='remote is broken on cygwin and hangs')
class RemoteArchiverTestCase(ArchiverTestCase):