@@ -109,6 +109,9 @@ def get_one_valid_targetinfo(
109
109
OSError: New metadata could not be written to disk
110
110
RepositoryError: Metadata failed to verify in some way
111
111
TODO: download-related errors
112
+
113
+ Returns:
114
+ A targetinfo dictionary or None
112
115
"""
113
116
return self ._preorder_depth_first_walk (target_path )
114
117
@@ -315,15 +318,17 @@ def _preorder_depth_first_walk(
315
318
target found in the most trusted role.
316
319
"""
317
320
318
- role_names = [("targets" , "root" )]
321
+ # List of delegations to be interrogated. A (role, parent role) pair
322
+ # is needed to load and verify the delegated targets metadata.
323
+ delegations_to_visit = [("targets" , "root" )]
319
324
visited_role_names : Set [Tuple [str , str ]] = set ()
320
325
number_of_delegations = self .config .max_delegations
321
326
322
327
# Preorder depth-first traversal of the graph of target delegations.
323
- while number_of_delegations > 0 and len (role_names ) > 0 :
328
+ while number_of_delegations > 0 and len (delegations_to_visit ) > 0 :
324
329
325
330
# Pop the role name from the top of the stack.
326
- role_name , parent_role = role_names .pop (- 1 )
331
+ role_name , parent_role = delegations_to_visit .pop (- 1 )
327
332
328
333
# Skip any visited current role to prevent cycles.
329
334
if (role_name , parent_role ) in visited_role_names :
@@ -360,19 +365,19 @@ def _preorder_depth_first_walk(
360
365
)
361
366
if child_role .terminating :
362
367
logger .debug ("Not backtracking to other roles." )
363
- role_names = []
368
+ delegations_to_visit = []
364
369
break
365
370
# Push 'child_roles_to_visit' in reverse order of appearance
366
- # onto 'role_names '. Roles are popped from the end of
367
- # the 'role_names' list.
371
+ # onto 'delegations_to_visit '. Roles are popped from the end of
372
+ # the list.
368
373
child_roles_to_visit .reverse ()
369
- role_names .extend (child_roles_to_visit )
374
+ delegations_to_visit .extend (child_roles_to_visit )
370
375
371
- if number_of_delegations == 0 and len (role_names ) > 0 :
376
+ if number_of_delegations == 0 and len (delegations_to_visit ) > 0 :
372
377
logger .debug (
373
378
"%d roles left to visit, but allowed to "
374
379
"visit at most %d delegations." ,
375
- len (role_names ),
380
+ len (delegations_to_visit ),
376
381
self .config .max_delegations ,
377
382
)
378
383
0 commit comments