@@ -170,6 +170,9 @@ def get_one_valid_targetinfo(
170170 OSError: New metadata could not be written to disk
171171 RepositoryError: Metadata failed to verify in some way
172172 TODO: download-related errors
173+
174+ Returns:
175+ A targetinfo dictionary or None
173176 """
174177 return self ._preorder_depth_first_walk (target_path )
175178
@@ -378,15 +381,17 @@ def _preorder_depth_first_walk(
378381 target found in the most trusted role.
379382 """
380383
381- role_names = [("targets" , "root" )]
384+ # List of delegations to be interrogated. A (role, parent role) pair
385+ # is needed to load and verify the delegated targets metadata.
386+ delegations_to_visit = [("targets" , "root" )]
382387 visited_role_names : Set [Tuple [str , str ]] = set ()
383388 number_of_delegations = self .config .max_delegations
384389
385390 # Preorder depth-first traversal of the graph of target delegations.
386- while number_of_delegations > 0 and len (role_names ) > 0 :
391+ while number_of_delegations > 0 and len (delegations_to_visit ) > 0 :
387392
388393 # Pop the role name from the top of the stack.
389- role_name , parent_role = role_names .pop (- 1 )
394+ role_name , parent_role = delegations_to_visit .pop (- 1 )
390395
391396 # Skip any visited current role to prevent cycles.
392397 if (role_name , parent_role ) in visited_role_names :
@@ -423,19 +428,19 @@ def _preorder_depth_first_walk(
423428 )
424429 if child_role .terminating :
425430 logger .debug ("Not backtracking to other roles." )
426- role_names = []
431+ delegations_to_visit = []
427432 break
428433 # Push 'child_roles_to_visit' in reverse order of appearance
429- # onto 'role_names '. Roles are popped from the end of
430- # the 'role_names' list.
434+ # onto 'delegations_to_visit '. Roles are popped from the end of
435+ # the list.
431436 child_roles_to_visit .reverse ()
432- role_names .extend (child_roles_to_visit )
437+ delegations_to_visit .extend (child_roles_to_visit )
433438
434- if number_of_delegations == 0 and len (role_names ) > 0 :
439+ if number_of_delegations == 0 and len (delegations_to_visit ) > 0 :
435440 logger .debug (
436441 "%d roles left to visit, but allowed to "
437442 "visit at most %d delegations." ,
438- len (role_names ),
443+ len (delegations_to_visit ),
439444 self .config .max_delegations ,
440445 )
441446
0 commit comments