@@ -170,6 +170,9 @@ def get_one_valid_targetinfo(
170
170
OSError: New metadata could not be written to disk
171
171
RepositoryError: Metadata failed to verify in some way
172
172
TODO: download-related errors
173
+
174
+ Returns:
175
+ A targetinfo dictionary or None
173
176
"""
174
177
return self ._preorder_depth_first_walk (target_path )
175
178
@@ -378,15 +381,17 @@ def _preorder_depth_first_walk(
378
381
target found in the most trusted role.
379
382
"""
380
383
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" )]
382
387
visited_role_names : Set [Tuple [str , str ]] = set ()
383
388
number_of_delegations = self .config .max_delegations
384
389
385
390
# 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 :
387
392
388
393
# 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 )
390
395
391
396
# Skip any visited current role to prevent cycles.
392
397
if (role_name , parent_role ) in visited_role_names :
@@ -423,19 +428,19 @@ def _preorder_depth_first_walk(
423
428
)
424
429
if child_role .terminating :
425
430
logger .debug ("Not backtracking to other roles." )
426
- role_names = []
431
+ delegations_to_visit = []
427
432
break
428
433
# 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.
431
436
child_roles_to_visit .reverse ()
432
- role_names .extend (child_roles_to_visit )
437
+ delegations_to_visit .extend (child_roles_to_visit )
433
438
434
- if number_of_delegations == 0 and len (role_names ) > 0 :
439
+ if number_of_delegations == 0 and len (delegations_to_visit ) > 0 :
435
440
logger .debug (
436
441
"%d roles left to visit, but allowed to "
437
442
"visit at most %d delegations." ,
438
- len (role_names ),
443
+ len (delegations_to_visit ),
439
444
self .config .max_delegations ,
440
445
)
441
446
0 commit comments