move check for write_handle to the beginning and raise exception when writing to a closed file handle

This commit is contained in:
Kay Kurokawa 2017-09-13 13:04:05 -04:00 committed by Jack Robison
parent 196aa24b8b
commit 468a16af58
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF

View file

@ -55,6 +55,10 @@ class HashBlobWriter(object):
return self._hashsum.hexdigest()
def write(self, data):
if self.write_handle is None:
log.info("writer has already been closed")
raise ValueError('I/O operation on closed file')
self._hashsum.update(data)
self.len_so_far += len(data)
if self.len_so_far > self.length_getter():
@ -64,9 +68,6 @@ class HashBlobWriter(object):
" %s to %s" % (self.len_so_far,
self.length_getter()))))
else:
if self.write_handle is None:
log.debug("Tried to write to a write_handle that was None.")
return
self.write_handle.write(data)
if self.len_so_far == self.length_getter():
self.finished_cb(self)