Skip to content

Commit e2db9d2

Browse files
committed
Remove mirror_*_download functions
mirror_target_download and mirror_meta_download functions that return iterators are causing more troubles than good. Since there is a need to download and verify each file inside the mirrors loop (before continuing to the next mirror), feels like the correct component to do this is the Updater itself. This means slightly repetitive code inside the Updater class but with the benefit of better readability and less bug-prone implementation. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent 101ab3d commit e2db9d2

File tree

2 files changed

+200
-162
lines changed

2 files changed

+200
-162
lines changed

tuf/client_rework/mirrors.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
"""
2424

2525
import os
26-
from typing import BinaryIO, Dict, TextIO
2726
from urllib import parse
2827

2928
from securesystemslib import exceptions as sslib_exceptions
3029
from securesystemslib import formats as sslib_formats
3130
from securesystemslib import util as sslib_util
3231

33-
from tuf import exceptions, formats
34-
from tuf.client_rework import download
32+
from tuf import formats
3533

3634
# The type of file to be downloaded from a repository. The
3735
# 'get_list_of_mirrors' function supports these file types.
@@ -130,67 +128,3 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
130128
list_of_mirrors.append(url.replace("\\", "/"))
131129

132130
return list_of_mirrors
133-
134-
135-
def mirror_meta_download(
136-
filename: str,
137-
upper_length: int,
138-
mirrors_config: Dict,
139-
fetcher: "FetcherInterface",
140-
) -> TextIO:
141-
"""
142-
Download metadata file from the list of metadata mirrors
143-
"""
144-
file_mirrors = get_list_of_mirrors("meta", filename, mirrors_config)
145-
146-
file_mirror_errors = {}
147-
for file_mirror in file_mirrors:
148-
try:
149-
temp_obj = download.download_file(
150-
file_mirror, upper_length, fetcher, strict_required_length=False
151-
)
152-
153-
temp_obj.seek(0)
154-
yield temp_obj
155-
156-
# pylint cannot figure out that we store the exceptions
157-
# in a dictionary to raise them later so we disable
158-
# the warning. This should be reviewed in the future still.
159-
except Exception as exception: # pylint: disable=broad-except
160-
file_mirror_errors[file_mirror] = exception
161-
162-
finally:
163-
if file_mirror_errors:
164-
raise exceptions.NoWorkingMirrorError(file_mirror_errors)
165-
166-
167-
def mirror_target_download(
168-
fileinfo: str, mirrors_config: Dict, fetcher: "FetcherInterface"
169-
) -> BinaryIO:
170-
"""
171-
Download target file from the list of target mirrors
172-
"""
173-
# full_filename = _get_full_name(filename)
174-
file_mirrors = get_list_of_mirrors(
175-
"target", fileinfo["filepath"], mirrors_config
176-
)
177-
178-
file_mirror_errors = {}
179-
for file_mirror in file_mirrors:
180-
try:
181-
temp_obj = download.download_file(
182-
file_mirror, fileinfo["fileinfo"]["length"], fetcher
183-
)
184-
185-
temp_obj.seek(0)
186-
yield temp_obj
187-
188-
# pylint cannot figure out that we store the exceptions
189-
# in a dictionary to raise them later so we disable
190-
# the warning. This should be reviewed in the future still.
191-
except Exception as exception: # pylint: disable=broad-except
192-
file_mirror_errors[file_mirror] = exception
193-
194-
finally:
195-
if file_mirror_errors:
196-
raise exceptions.NoWorkingMirrorError(file_mirror_errors)

0 commit comments

Comments
 (0)