Skip to content

Commit

Permalink
client: simplify loop exit logic
Browse files Browse the repository at this point in the history
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 <jlock@vmware.com>
  • Loading branch information
joshuagl committed Nov 26, 2020
1 parent 02416e3 commit 372e218
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tuf/client/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,23 +1327,18 @@ def _get_target_file(self, target_filepath, file_length, file_hashes,
# Verify 'file_object' against the expected length and hashes.
self._check_file_length(file_object, file_length)
self._check_hashes(file_object, file_hashes)
# If the file verifies, we don't need to try more mirrors
return file_object

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

else:
break

if file_object:
return file_object

else:
logger.debug('Failed to update ' + repr(target_filepath) + ' from'
' all mirrors: ' + repr(file_mirror_errors))
raise tuf.exceptions.NoWorkingMirrorError(file_mirror_errors)
logger.debug('Failed to update ' + repr(target_filepath) + ' from'
' all mirrors: ' + repr(file_mirror_errors))
raise tuf.exceptions.NoWorkingMirrorError(file_mirror_errors)



Expand Down

0 comments on commit 372e218

Please sign in to comment.