Skip to content

Commit f70a4c0

Browse files
Jussi KukkonenMVrachev
authored andcommitted
Updater: Close temp file in exception cases
If during updater.download_target() the download succeeds but a later check fails (e.g. BadHashError), remember to close the tempfile. Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
1 parent 488410c commit f70a4c0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tuf/client/updater.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,12 @@ def _get_target_file(self, target_filepath, file_length, file_hashes,
13201320
return file_object
13211321

13221322
except Exception as exception:
1323-
# Remember the error from this mirror, and "reset" the target file.
1323+
# Remember the error from this mirror, close tempfile if one was opened
13241324
logger.debug('Update failed from ' + file_mirror + '.')
13251325
file_mirror_errors[file_mirror] = exception
1326-
file_object = None
1326+
if file_object is not None:
1327+
file_object.close()
1328+
file_object = None
13271329

13281330
logger.debug('Failed to update ' + repr(target_filepath) + ' from'
13291331
' all mirrors: ' + repr(file_mirror_errors))

0 commit comments

Comments
 (0)