Skip to content

Commit 41da27b

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 c0df590 commit 41da27b

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

tuf/ngclient/updater.py

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

346346
if target is None:
347-
348347
child_roles_to_visit = []
349348
# NOTE: This may be a slow operation if there are many
350349
# delegated roles.
351350
for child_role in child_roles:
352351
if child_role.is_in_trusted_paths(target_filepath):
353-
child_role_name = child_role.name
354-
else:
355-
child_role_name = None
356352

357-
if child_role.terminating and child_role_name is not None:
358-
logger.debug(
359-
"Adding child role %s.\n"
360-
"Not backtracking to other roles.",
361-
child_role_name,
362-
)
363-
role_names = []
353+
logger.debug("Adding child role %s", child_role.name)
354+
364355
child_roles_to_visit.append(
365-
(child_role_name, role_name)
356+
(child_role.name, role_name)
366357
)
367-
break
368358

369-
if child_role_name is None:
370-
logger.debug("Skipping child role %s", child_role_name)
359+
if child_role.terminating:
360+
logger.debug("Not backtracking to other roles.")
361+
role_names = []
362+
break
371363

372364
else:
373-
logger.debug("Adding child role %s", child_role_name)
374-
child_roles_to_visit.append(
375-
(child_role_name, role_name)
376-
)
365+
logger.debug("Skipping child role %s", child_role.name)
377366

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

0 commit comments

Comments
 (0)