Skip to content

Commit 3943411

Browse files
committed
Simplify child roles loop
Simplify the code in _preorder_depth_first_walk. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
1 parent 45cc43c commit 3943411

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

tuf/ngclient/updater.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -407,36 +407,25 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict:
407407
child_roles = role_metadata.delegations.roles
408408

409409
if target is None:
410-
411410
child_roles_to_visit = []
412411
# NOTE: This may be a slow operation if there are many
413412
# delegated roles.
414413
for child_role in child_roles:
415414
if child_role.is_in_trusted_paths(target_filepath):
416-
child_role_name = child_role.name
417-
else:
418-
child_role_name = None
419415

420-
if child_role.terminating and child_role_name is not None:
421-
logger.debug(
422-
"Adding child role %s.\n"
423-
"Not backtracking to other roles.",
424-
child_role_name,
425-
)
426-
role_names = []
416+
logger.debug("Adding child role %s", child_role.name)
417+
427418
child_roles_to_visit.append(
428-
(child_role_name, role_name)
419+
(child_role.name, role_name)
429420
)
430-
break
431421

432-
if child_role_name is None:
433-
logger.debug("Skipping child role %s", child_role_name)
422+
if child_role.terminating:
423+
logger.debug("Not backtracking to other roles.")
424+
role_names = []
425+
break
434426

435427
else:
436-
logger.debug("Adding child role %s", child_role_name)
437-
child_roles_to_visit.append(
438-
(child_role_name, role_name)
439-
)
428+
logger.debug("Skipping child role %s", child_role.name)
440429

441430
# Push 'child_roles_to_visit' in reverse order of appearance
442431
# onto 'role_names'. Roles are popped from the end of

0 commit comments

Comments
 (0)