mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
updater: more optimal file length checking
Rather than read to the end of the file in order to determin its size, use the whence value of seek() to move the file object's position to the end of the file, then the tell() method of the file object to read the current position in bytes. Co-authored-by: Jussi Kukkonen <jkukkonen@vmware.com> Signed-off-by: Joshua Lock <jlock@vmware.com>
This commit is contained in:
parent
ad1335b6ed
commit
02416e3376
1 changed files with 4 additions and 2 deletions
|
|
@ -1244,8 +1244,10 @@ def _check_file_length(self, file_object, trusted_file_length):
|
|||
None.
|
||||
"""
|
||||
|
||||
file_object.seek(0)
|
||||
observed_length = len(file_object.read())
|
||||
# seek to the end of the file; that is offset 0 from the end of the file,
|
||||
# represented by a whence value of 2
|
||||
file_object.seek(0, 2)
|
||||
observed_length = file_object.tell()
|
||||
|
||||
# Return and log a message if the length 'file_object' is equal to
|
||||
# 'trusted_file_length', otherwise raise an exception. A hard check
|
||||
|
|
|
|||
Loading…
Reference in a new issue