From adb5ea003ec895b01fa1a6e7b0c0a0b2f6aec74f Mon Sep 17 00:00:00 2001 From: vladdd Date: Wed, 7 Aug 2013 19:30:22 -0400 Subject: [PATCH] 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. --- tuf/client/updater.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tuf/client/updater.py b/tuf/client/updater.py index 97582c4f..7d7c633a 100755 --- a/tuf/client/updater.py +++ b/tuf/client/updater.py @@ -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. 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', {})