Skip to content

Commit ef5cce9

Browse files
committed
Rename targetpath to path and make it mandatory
Signed-off-by: Martin Vrachev <[email protected]>
1 parent bb0dc23 commit ef5cce9

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

tuf/api/metadata.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1085,15 +1085,15 @@ class TargetFile(BaseFile):
10851085
Attributes:
10861086
length: An integer indicating the length of the target file.
10871087
hashes: A dictionary of hash algorithm names to hash values.
1088-
targetname: An optional string denoting the target file name.
1088+
path: A string denoting the target file path.
10891089
unrecognized_fields: Dictionary of all unrecognized fields.
10901090
"""
10911091

10921092
def __init__(
10931093
self,
10941094
length: int,
10951095
hashes: Dict[str, str],
1096-
targetname: Optional[str] = None,
1096+
path: str,
10971097
unrecognized_fields: Optional[Mapping[str, Any]] = None,
10981098
) -> None:
10991099

@@ -1102,23 +1102,21 @@ def __init__(
11021102

11031103
self.length = length
11041104
self.hashes = hashes
1105-
self.targetname = targetname
1105+
self.path = path
11061106
self.unrecognized_fields = unrecognized_fields or {}
11071107

11081108
@property
11091109
def custom(self) -> Any:
11101110
return self.unrecognized_fields.get("custom", None)
11111111

11121112
@classmethod
1113-
def from_dict(
1114-
cls, target_dict: Dict[str, Any], targetname: Optional[str] = None
1115-
) -> "TargetFile":
1113+
def from_dict(cls, target_dict: Dict[str, Any], path: str) -> "TargetFile":
11161114
"""Creates TargetFile object from its dict representation."""
11171115
length = target_dict.pop("length")
11181116
hashes = target_dict.pop("hashes")
11191117

11201118
# All fields left in the target_dict are unrecognized.
1121-
return cls(length, hashes, targetname, target_dict)
1119+
return cls(length, hashes, path, target_dict)
11221120

11231121
def to_dict(self) -> Dict[str, Any]:
11241122
"""Returns the JSON-serializable dictionary representation of self."""
@@ -1184,7 +1182,9 @@ def from_dict(cls, signed_dict: Dict[str, Any]) -> "Targets":
11841182
delegations = Delegations.from_dict(delegations_dict)
11851183
res_targets = {}
11861184
for target_path, target_info in targets.items():
1187-
res_targets[target_path] = TargetFile.from_dict(target_info)
1185+
res_targets[target_path] = TargetFile.from_dict(
1186+
target_info, target_path
1187+
)
11881188
# All fields left in the targets_dict are unrecognized.
11891189
return cls(*common_args, res_targets, delegations, signed_dict)
11901190

tuf/ngclient/updater.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ def updated_targets(
199199
# against each hash listed for its fileinfo. Note: join() discards
200200
# 'destination_directory' if 'filepath' contains a leading path
201201
# separator (i.e., is treated as an absolute path).
202-
target_filepath = os.path.join(
203-
destination_directory, target.targetname
204-
)
202+
target_filepath = os.path.join(destination_directory, target.path)
205203

206204
if target_filepath in updated_targetpaths:
207205
continue
@@ -248,7 +246,7 @@ def download_target(
248246
else:
249247
target_base_url = _ensure_trailing_slash(target_base_url)
250248

251-
target_filepath = targetinfo.targetname
249+
target_filepath = targetinfo.path
252250
full_url = parse.urljoin(target_base_url, target_filepath)
253251

254252
with self._fetcher.download_file(
@@ -459,7 +457,6 @@ def _preorder_depth_first_walk(self, target_filepath) -> TargetFile:
459457
self.config.max_delegations,
460458
)
461459

462-
target.targetname = target_filepath
463460
return target
464461

465462

0 commit comments

Comments
 (0)