Skip to content

Commit 372e218

Browse files
committed
client: simplify loop exit logic
Simplify the loop exit logic in _get_target_file() to simply return a verified file_object, once we have it, rather than breaking from the loop and then returning the file_object. This converts a use of a try/except/else to a try/except and is a little easier to read. Signed-off-by: Joshua Lock <[email protected]>
1 parent 02416e3 commit 372e218

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

tuf/client/updater.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,23 +1327,18 @@ def _get_target_file(self, target_filepath, file_length, file_hashes,
13271327
# Verify 'file_object' against the expected length and hashes.
13281328
self._check_file_length(file_object, file_length)
13291329
self._check_hashes(file_object, file_hashes)
1330+
# If the file verifies, we don't need to try more mirrors
1331+
return file_object
13301332

13311333
except Exception as exception:
13321334
# Remember the error from this mirror, and "reset" the target file.
13331335
logger.debug('Update failed from ' + file_mirror + '.')
13341336
file_mirror_errors[file_mirror] = exception
13351337
file_object = None
13361338

1337-
else:
1338-
break
1339-
1340-
if file_object:
1341-
return file_object
1342-
1343-
else:
1344-
logger.debug('Failed to update ' + repr(target_filepath) + ' from'
1345-
' all mirrors: ' + repr(file_mirror_errors))
1346-
raise tuf.exceptions.NoWorkingMirrorError(file_mirror_errors)
1339+
logger.debug('Failed to update ' + repr(target_filepath) + ' from'
1340+
' all mirrors: ' + repr(file_mirror_errors))
1341+
raise tuf.exceptions.NoWorkingMirrorError(file_mirror_errors)
13471342

13481343

13491344

0 commit comments

Comments
 (0)