Minor edits to PR #318 (prevent cycles when visiting roles)

This commit is contained in:
Vladimir Diaz 2016-06-09 10:58:19 -04:00
parent b9e83a2e8a
commit 8bd9ca8a8d

View file

@ -2644,14 +2644,15 @@ def _preorder_depth_first_walk(self, target_filepath):
# the top-level metadata have been refreshed (i.e., updater.refresh()).
self._update_metadata_if_changed('targets')
# Preorder depth-first traversal of the tree of target delegations.
# Preorder depth-first traversal of the graph of target delegations.
while target is None and number_of_delegations > 0 and len(role_names) > 0:
# Pop the role name from the top of the stack.
role_name = role_names.pop(-1)
# Skip any visited current role.
# Skip any visited current role to prevent cycles.
if role_name in visited_role_names:
logger.debug('Skipping visited current role '+repr(role_name))
logger.debug('Skipping visited current role ' + repr(role_name))
continue
# The metadata for 'role_name' must be downloaded/updated before its
@ -2670,6 +2671,7 @@ def _preorder_depth_first_walk(self, target_filepath):
target_filepath)
# After preorder check, add current role to set of visited roles.
visited_role_names.add(role_name)
# And also decrement number of visited roles.
number_of_delegations -= 1
@ -2704,9 +2706,9 @@ def _preorder_depth_first_walk(self, target_filepath):
logger.debug('Found target in current role ' + repr(role_name))
if target is None and number_of_delegations == 0 and len(role_names) > 0:
logger.debug(repr(len(role_names))+' roles left to visit, '+
'but allowed to visit at most '+
repr(tuf.conf.MAX_NUMBER_OF_DELEGATIONS)+' delegations.')
logger.debug(repr(len(role_names)) + ' roles left to visit, ' +
'but allowed to visit at most ' +
repr(tuf.conf.MAX_NUMBER_OF_DELEGATIONS) + ' delegations.')
return target