Gracefully handle exceptions while writing a file during a receive mode transfer (like out of disk space error)

This commit is contained in:
Micah Lee 2019-02-12 14:36:14 -08:00
parent 28eaf2f2be
commit 09c2696c27
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -193,10 +193,15 @@ class ReceiveModeFile(object):
"""
if self.upload_error or (not self.onionshare_request.stop_q.empty()):
self.close()
self.onionshare_request.close()
self.onionshare_request.close(self.upload_error)
return
try:
bytes_written = self.f.write(b)
except:
# If we can't write the file, close early
self.upload_error = True
return
self.onionshare_write_func(self.onionshare_filename, bytes_written)
def close(self):
@ -394,8 +399,12 @@ class ReceiveModeRequest(Request):
'progress': self.progress
})
def file_close_func(self, filename):
def file_close_func(self, filename, upload_error=False):
"""
This function gets called when a specific file is closed.
"""
self.progress[filename]['complete'] = True
# If the file tells us there was an upload error, let the request know as well
if upload_error:
self.upload_error = True