Skip to content

Commit 882df8e

Browse files
committed
Remove unnecessary variables
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]>
1 parent f035cf4 commit 882df8e

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

tuf/repository_tool.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,8 @@ def add_paths(self, paths, child_rolename):
18541854
securesystemslib.exceptions.Error, if 'child_rolename' has not been
18551855
delegated yet.
18561856
1857-
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
1857+
tuf.exceptions.InvalidNameError, if any path in 'paths' does not match
1858+
pattern.
18581859
18591860
<Side Effects>
18601861
Modifies this Targets' delegations field.
@@ -1870,10 +1871,6 @@ def add_paths(self, paths, child_rolename):
18701871
securesystemslib.formats.PATHS_SCHEMA.check_match(paths)
18711872
tuf.formats.ROLENAME_SCHEMA.check_match(child_rolename)
18721873

1873-
# A list of relative and verified paths or glob patterns to be added to the
1874-
# child role's entry in the parent's delegations field.
1875-
relative_paths = []
1876-
18771874
# Ensure that 'child_rolename' exists, otherwise it will not have an entry
18781875
# in the parent role's delegations field.
18791876
if not tuf.roledb.role_exists(child_rolename, self._repository_name):
@@ -1886,7 +1883,6 @@ def add_paths(self, paths, child_rolename):
18861883
# on the file system is not verified. If the path is incorrect,
18871884
# the targetfile won't be matched successfully during a client update.
18881885
self._check_path(path)
1889-
relative_paths.append(path)
18901886

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

@@ -1944,7 +1940,7 @@ def add_target(self, filepath, custom=None, fileinfo=None):
19441940
securesystemslib.exceptions.FormatError, if 'filepath' is improperly
19451941
formatted.
19461942
1947-
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
1943+
tuf.exceptions.InvalidNameError, if 'filepath' does not match pattern.
19481944
19491945
<Side Effects>
19501946
Adds 'filepath' to this role's list of targets. This role's
@@ -2024,7 +2020,8 @@ def add_targets(self, list_of_targets):
20242020
securesystemslib.exceptions.FormatError, if the arguments are improperly
20252021
formatted.
20262022
2027-
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
2023+
tuf.exceptions.InvalidNameError, if any target in 'list_of_targets'
2024+
does not match pattern.
20282025
20292026
<Side Effects>
20302027
This Targets' roleinfo is updated with the paths in 'list_of_targets'.
@@ -2039,9 +2036,6 @@ def add_targets(self, list_of_targets):
20392036
# Raise 'securesystemslib.exceptions.FormatError' if there is a mismatch.
20402037
tuf.formats.RELPATHS_SCHEMA.check_match(list_of_targets)
20412038

2042-
# Update the tuf.roledb entry.
2043-
relative_list_of_targets = []
2044-
20452039
# Ensure the paths in 'list_of_targets' are relative and use forward slash
20462040
# as a separator or raise an exception. The paths of 'list_of_targets'
20472041
# will be verified as existing and allowed paths according to this Targets
@@ -2050,14 +2044,12 @@ def add_targets(self, list_of_targets):
20502044
# in any order and minimize the number of times these checks are performed.
20512045
for target in list_of_targets:
20522046
self._check_path(target)
2053-
relative_list_of_targets.append(target)
20542047

20552048
# Update this Targets 'tuf.roledb.py' entry.
20562049
roleinfo = tuf.roledb.get_roleinfo(self._rolename, self._repository_name)
2057-
for relative_target in relative_list_of_targets:
2050+
for relative_target in list_of_targets:
20582051
if relative_target not in roleinfo['paths']:
20592052
logger.debug('Adding new target: ' + repr(relative_target))
2060-
20612053
else:
20622054
logger.debug('Replacing target: ' + repr(relative_target))
20632055
roleinfo['paths'].update({relative_target: {}})
@@ -2285,7 +2277,8 @@ def delegate(self, rolename, public_keys, paths, threshold=1,
22852277
22862278
securesystemslib.exceptions.Error, if the delegated role already exists.
22872279
2288-
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
2280+
tuf.exceptions.InvalidNameError, if any path in 'paths' or target in
2281+
'list_of_targets' does not match pattern.
22892282
22902283
<Side Effects>
22912284
A new Target object is created for 'rolename' that is accessible to the
@@ -2490,7 +2483,8 @@ def delegate_hashed_bins(self, list_of_targets, keys_of_hashed_bins,
24902483
2, or one of the targets in 'list_of_targets' is not relative to the
24912484
repository's targets directory.
24922485
2493-
tuf.exceptions.InvalidNameError, if 'pathname' does not match pattern.
2486+
tuf.exceptions.InvalidNameError, if any target in 'list_of_targets'
2487+
does not match pattern.
24942488
24952489
<Side Effects>
24962490
Delegates multiple target roles from the current parent role.

0 commit comments

Comments
 (0)