Merge pull request #1173 from jku/add-missing-local-repository-error

Add MissingLocalRepositoryError
This commit is contained in:
Joshua Lock 2020-10-15 10:35:39 +01:00 committed by GitHub
commit b57aa5857b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -224,6 +224,9 @@ def test_1__init__exceptions(self):
# directory.
tuf.settings.repositories_directory = self.client_directory
# Test: repository does not exist
self.assertRaises(tuf.exceptions.MissingLocalRepositoryError, updater.Updater,
'test_non_existing_repository', self.repository_mirrors)
# Test: empty client repository (i.e., no metadata directory).
metadata_backup = self.client_metadata + '.backup'

View file

@ -727,6 +727,12 @@ def __init__(self, repository_name, repository_mirrors):
# Set the path for the current set of metadata files.
repositories_directory = tuf.settings.repositories_directory
repository_directory = os.path.join(repositories_directory, self.repository_name)
# raise MissingLocalRepository if the repo does not exist at all.
if not os.path.exists(repository_directory):
raise tuf.exceptions.MissingLocalRepositoryError('Local repository ' +
repr(repository_directory) + ' does not exist.')
current_path = os.path.join(repository_directory, 'metadata', 'current')
# Ensure the current path is valid/exists before saving it.

View file

@ -115,6 +115,10 @@ class RepositoryError(Error):
"""Indicate an error with a repository's state, such as a missing file."""
class MissingLocalRepositoryError(RepositoryError):
"""Raised when a local repository could not be found."""
class InsufficientKeysError(Error):
"""Indicate that metadata role lacks a threshold of pubic or private keys."""