diff options
author | Micah Lee <micah@micahflee.com> | 2019-01-21 17:28:24 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2019-01-21 17:28:24 -0800 |
commit | f4cd49e9dcce92f65dd881c38a7101f39ed19075 (patch) | |
tree | 2332d49f3bc7a2711f7433533b3122e468c59a60 /onionshare | |
parent | 1be10f1e0268567c3fc7d19f4b9a1692e8f38fb7 (diff) | |
parent | 6af9a8a1cd81ca171304d3dfe83e388e45b9183d (diff) | |
download | onionshare-f4cd49e9dcce92f65dd881c38a7101f39ed19075.tar.gz onionshare-f4cd49e9dcce92f65dd881c38a7101f39ed19075.zip |
Merge branch 'develop' into 866_receive_mode_crash
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/web/receive_mode.py | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index ad72c9f4..450417f6 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -65,6 +65,21 @@ class ReceiveModeWeb(object): date_dir = now.strftime("%Y-%m-%d") time_dir = now.strftime("%H.%M.%S") receive_mode_dir = os.path.join(self.common.settings.get('data_dir'), date_dir, time_dir) + valid = True + try: + os.makedirs(receive_mode_dir, 0o700, exist_ok=True) + except PermissionError: + self.web.add_request(self.web.REQUEST_ERROR_DATA_DIR_CANNOT_CREATE, request.path, { + "receive_mode_dir": receive_mode_dir + }) + print(strings._('error_cannot_create_data_dir').format(receive_mode_dir)) + valid = False + if not valid: + flash('Error uploading, please inform the OnionShare user', 'error') + if self.common.settings.get('public_mode'): + return redirect('/') + else: + return redirect('/{}'.format(slug_candidate)) files = request.files.getlist('file[]') filenames = [] @@ -290,13 +305,8 @@ class ReceiveModeRequest(Request): strings._("receive_mode_upload_starting").format(self.web.common.human_readable_filesize(self.content_length)) )) - # Tell the GUI - self.web.add_request(self.web.REQUEST_STARTED, self.path, { - 'id': self.upload_id, - 'content_length': self.content_length - }) - - self.web.receive_mode.uploads_in_progress.append(self.upload_id) + # Don't tell the GUI that a request has started until we start receiving files + self.told_gui_about_request = False self.previous_file = None @@ -306,6 +316,16 @@ class ReceiveModeRequest(Request): writable stream. """ if self.upload_request: + if not self.told_gui_about_request: + # Tell the GUI about the request + self.web.add_request(self.web.REQUEST_STARTED, self.path, { + 'id': self.upload_id, + 'content_length': self.content_length + }) + self.web.receive_mode.uploads_in_progress.append(self.upload_id) + + self.told_gui_about_request = True + self.progress[filename] = { 'uploaded_bytes': 0, 'complete': False @@ -327,6 +347,7 @@ class ReceiveModeRequest(Request): self.web.common.log('ReceiveModeRequest', 'close') try: +<<<<<<< HEAD upload_id = self.upload_id if not self.web.stop_q.empty(): @@ -335,12 +356,20 @@ class ReceiveModeRequest(Request): 'id': upload_id }) else: +======= + if self.told_gui_about_request: + upload_id = self.upload_id +>>>>>>> develop # Inform the GUI that the upload has finished self.web.add_request(self.web.REQUEST_UPLOAD_FINISHED, self.path, { 'id': upload_id }) +<<<<<<< HEAD self.web.receive_mode.uploads_in_progress.remove(upload_id) +======= + self.web.receive_mode.uploads_in_progress.remove(upload_id) +>>>>>>> develop except AttributeError: pass @@ -365,10 +394,11 @@ class ReceiveModeRequest(Request): ), end='') # Update the GUI on the upload progress - self.web.add_request(self.web.REQUEST_PROGRESS, self.path, { - 'id': self.upload_id, - 'progress': self.progress - }) + if self.told_gui_about_request: + self.web.add_request(self.web.REQUEST_PROGRESS, self.path, { + 'id': self.upload_id, + 'progress': self.progress + }) def file_close_func(self, filename): """ |