Skip to content

Commit

Permalink
Remove unnecessary variables
Browse files Browse the repository at this point in the history
Remove unnecessary copying of paths to another list in
add_targets() and add_paths() methods.

Fix incorrect docstring text.

Signed-off-by: Teodora Sechkova <[email protected]>
  • Loading branch information
sechkova committed Apr 8, 2020
1 parent f035cf4 commit 882df8e
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions tuf/repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,8 @@ def add_paths(self, paths, child_rolename):
securesystemslib.exceptions.Error, if 'child_rolename' has not been
delegated yet.
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
tuf.exceptions.InvalidNameError, if any path in 'paths' does not match
pattern.
<Side Effects>
Modifies this Targets' delegations field.
Expand All @@ -1870,10 +1871,6 @@ def add_paths(self, paths, child_rolename):
securesystemslib.formats.PATHS_SCHEMA.check_match(paths)
tuf.formats.ROLENAME_SCHEMA.check_match(child_rolename)

# A list of relative and verified paths or glob patterns to be added to the
# child role's entry in the parent's delegations field.
relative_paths = []

# Ensure that 'child_rolename' exists, otherwise it will not have an entry
# in the parent role's delegations field.
if not tuf.roledb.role_exists(child_rolename, self._repository_name):
Expand All @@ -1886,7 +1883,6 @@ def add_paths(self, paths, child_rolename):
# on the file system is not verified. If the path is incorrect,
# the targetfile won't be matched successfully during a client update.
self._check_path(path)
relative_paths.append(path)

# Get the current role's roleinfo, so that its delegations field can be
# updated.
Expand All @@ -1895,7 +1891,7 @@ def add_paths(self, paths, child_rolename):
# Update the delegated paths of 'child_rolename' to add relative paths.
for role in roleinfo['delegations']['roles']:
if role['name'] == child_rolename:
for relative_path in relative_paths:
for relative_path in paths:
if relative_path not in role['paths']:
role['paths'].append(relative_path)

Expand Down Expand Up @@ -1944,7 +1940,7 @@ def add_target(self, filepath, custom=None, fileinfo=None):
securesystemslib.exceptions.FormatError, if 'filepath' is improperly
formatted.
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
tuf.exceptions.InvalidNameError, if 'filepath' does not match pattern.
<Side Effects>
Adds 'filepath' to this role's list of targets. This role's
Expand Down Expand Up @@ -2024,7 +2020,8 @@ def add_targets(self, list_of_targets):
securesystemslib.exceptions.FormatError, if the arguments are improperly
formatted.
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
tuf.exceptions.InvalidNameError, if any target in 'list_of_targets'
does not match pattern.
<Side Effects>
This Targets' roleinfo is updated with the paths in 'list_of_targets'.
Expand All @@ -2039,9 +2036,6 @@ def add_targets(self, list_of_targets):
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)

# Update the tuf.roledb entry.
relative_list_of_targets = []

# Ensure the paths in 'list_of_targets' are relative and use forward slash
# as a separator or raise an exception. The paths of 'list_of_targets'
# will be verified as existing and allowed paths according to this Targets
Expand All @@ -2050,14 +2044,12 @@ def add_targets(self, list_of_targets):
# in any order and minimize the number of times these checks are performed.
for target in list_of_targets:
self._check_path(target)
relative_list_of_targets.append(target)

# Update this Targets 'tuf.roledb.py' entry.
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
for relative_target in relative_list_of_targets:
for relative_target in list_of_targets:
if relative_target not in roleinfo['paths']:
logger.debug('Adding new target: ' + repr(relative_target))

else:
logger.debug('Replacing target: ' + repr(relative_target))
roleinfo['paths'].update({relative_target: {}})
Expand Down Expand Up @@ -2285,7 +2277,8 @@ def delegate(self, rolename, public_keys, paths, threshold=1,
securesystemslib.exceptions.Error, if the delegated role already exists.
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
tuf.exceptions.InvalidNameError, if any path in 'paths' or target in
'list_of_targets' does not match pattern.
<Side Effects>
A new Target object is created for 'rolename' that is accessible to the
Expand Down Expand Up @@ -2490,7 +2483,8 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
2, or one of the targets in 'list_of_targets' is not relative to the
repository's targets directory.
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
tuf.exceptions.InvalidNameError, if any target in 'list_of_targets'
does not match pattern.
<Side Effects>
Delegates multiple target roles from the current parent role.
Expand Down

0 comments on commit 882df8e

Please sign in to comment.