Skip to content

Commit b502434

Browse files
committed
Improve naming and comments
Give 'role_names' the more verbose description 'delegations_to_visit'. Add some comments and docstrings. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent 2159b88 commit b502434

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tuf/ngclient/updater.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def get_one_valid_targetinfo(
109109
OSError: New metadata could not be written to disk
110110
RepositoryError: Metadata failed to verify in some way
111111
TODO: download-related errors
112+
113+
Returns:
114+
A targetinfo dictionary or None
112115
"""
113116
return self._preorder_depth_first_walk(target_path)
114117

@@ -315,15 +318,17 @@ def _preorder_depth_first_walk(
315318
target found in the most trusted role.
316319
"""
317320

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")]
319324
visited_role_names: Set[Tuple[str, str]] = set()
320325
number_of_delegations = self.config.max_delegations
321326

322327
# 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:
324329

325330
# 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)
327332

328333
# Skip any visited current role to prevent cycles.
329334
if (role_name, parent_role) in visited_role_names:
@@ -360,19 +365,19 @@ def _preorder_depth_first_walk(
360365
)
361366
if child_role.terminating:
362367
logger.debug("Not backtracking to other roles.")
363-
role_names = []
368+
delegations_to_visit = []
364369
break
365370
# 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.
368373
child_roles_to_visit.reverse()
369-
role_names.extend(child_roles_to_visit)
374+
delegations_to_visit.extend(child_roles_to_visit)
370375

371-
if number_of_delegations == 0 and len(role_names) > 0:
376+
if number_of_delegations == 0 and len(delegations_to_visit) > 0:
372377
logger.debug(
373378
"%d roles left to visit, but allowed to "
374379
"visit at most %d delegations.",
375-
len(role_names),
380+
len(delegations_to_visit),
376381
self.config.max_delegations,
377382
)
378383

0 commit comments

Comments
 (0)