@@ -188,31 +188,27 @@ def updated_targets(
188
188
returned in a list. The list items can be downloaded with
189
189
'download_target()'.
190
190
"""
191
- # Keep track of the target objects and filepaths of updated targets.
192
- # Return 'updated_targets' and use 'updated_targetpaths' to avoid
193
- # duplicates.
194
- updated_targets = []
195
- updated_targetpaths = []
191
+ # Keep track of TargetFiles and local paths. Return 'updated_targets'
192
+ # and use 'local_paths' to avoid duplicates.
193
+ updated_targets : List [TargetFile ] = []
194
+ local_paths : List [str ] = []
196
195
197
196
for target in targets :
198
- # Prepend 'destination_directory' to the target's relative filepath
199
- # (as stored in metadata.) Verify the hash of 'target_filepath'
200
- # against each hash listed for its fileinfo. Note: join() discards
201
- # 'destination_directory' if 'filepath' contains a leading path
202
- # separator (i.e., is treated as an absolute path).
203
- target_filepath = os .path .join (destination_directory , target .path )
204
-
205
- if target_filepath in updated_targetpaths :
197
+ # URL encode to get local filename like download_target() does
198
+ filename = parse .quote (target .path , "" )
199
+ local_path = os .path .join (destination_directory , filename )
200
+
201
+ if local_path in local_paths :
206
202
continue
207
203
208
204
try :
209
- with open (target_filepath , "rb" ) as target_file :
205
+ with open (local_path , "rb" ) as target_file :
210
206
target .verify_length_and_hashes (target_file )
211
207
# If the file does not exist locally or length and hashes
212
208
# do not match, append to updated targets.
213
209
except (OSError , exceptions .LengthOrHashMismatchError ):
214
210
updated_targets .append (target )
215
- updated_targetpaths .append (target_filepath )
211
+ local_paths .append (local_path )
216
212
217
213
return updated_targets
218
214
@@ -221,7 +217,7 @@ def download_target(
221
217
targetinfo : TargetFile ,
222
218
destination_directory : str ,
223
219
target_base_url : Optional [str ] = None ,
224
- ) -> None :
220
+ ) -> str :
225
221
"""Downloads the target file specified by 'targetinfo'.
226
222
227
223
Args:
@@ -236,6 +232,9 @@ def download_target(
236
232
Raises:
237
233
TODO: download-related errors
238
234
TODO: file write errors
235
+
236
+ Returns:
237
+ Path to downloaded file
239
238
"""
240
239
241
240
if target_base_url is None :
@@ -266,12 +265,13 @@ def download_target(
266
265
f"{ target_filepath } length or hashes do not match"
267
266
) from e
268
267
269
- # Store the target file name without the HASH prefix.
270
- local_filepath = os .path .join (
271
- destination_directory , targetinfo .path
272
- )
268
+ # Use a URL encoded targetpath as the local filename
269
+ filename = parse .quote (targetinfo .path , "" )
270
+ local_filepath = os .path .join (destination_directory , filename )
273
271
sslib_util .persist_temp_file (target_file , local_filepath )
274
272
273
+ return local_filepath
274
+
275
275
def _download_metadata (
276
276
self , rolename : str , length : int , version : Optional [int ] = None
277
277
) -> bytes :
0 commit comments