Preliminary update preceding the major path_hash_prefix changes

This update addresses issue #86.  It begins by removing the wholesale downloading of all targets metadata and only downloads & verifies the metadata for the roles it only needs; the "lazy walk" scheme.
This commit is contained in:
vladdd 2013-08-07 19:30:22 -04:00
parent 1cd9b1251e
commit adb5ea003e

View file

@ -1512,6 +1512,9 @@ def target(self, target_filepath):
Exception:
In case of an unforeseen runtime error.
TODO: Update these exceptions once the final 'path_hash_prefix'
changes have been implemented.
<Side Effects>
The metadata for updated delegated roles are downloaded and stored.
@ -1526,8 +1529,13 @@ def target(self, target_filepath):
# Raise 'tuf.FormatError' if there is a mismatch.
tuf.formats.RELPATH_SCHEMA.check_match(target_filepath)
# Refresh the target metadata for all the delegated roles.
#self._refresh_targets_metadata(include_delegations=True)
# Ensure the client has the most up-to-date version of 'targets.txt'.
# Raise 'tuf.MetadataNotAvailableError' if the changed metadata
# cannot be successfully downloaded and 'tuf.RepositoryError' if the
# referenced metadata is missing. Target methods such as this one
# are called after the top-level metadata have been refreshed (i.e.,
# updater.refresh()).
self._update_metadata_if_changed('targets')
# The target is assumed to be missing until proven otherwise.
target = None
@ -1540,6 +1548,14 @@ def target(self, target_filepath):
while len(role_names) > 0 and target is None:
# Pop the role name from the top of the stack.
role_name = role_names.pop(-1)
# The metadata for 'role_name' must be downloaded/updated before
# its targets, delegations, and child roles can be inspected.
# self.metadata['current'][role_name] is currently missing.
# _refresh_targets_metadata() does not refresh 'targets.txt', it
# expects _update_metadata_if_changed() to have already refreshed it,
# which this function has checked above.
self._refresh_targets_metadata(role_name, include_delegations=False)
role_metadata = current_metadata[role_name]
targets = role_metadata['targets']
delegations = role_metadata.get('delegations', {})