diff options
author | Micah Lee <micah@micahflee.com> | 2021-04-30 15:57:11 -0700 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2021-04-30 15:57:11 -0700 |
commit | 89bed3c5ac02b2a4b0324fd0e68aaf4756ae8a35 (patch) | |
tree | e79e51e6038cd3c1a944a973db6548d40e4d660c | |
parent | 95e6985f865a57b97d40c8a7c35c77505d0750d2 (diff) | |
download | onionshare-89bed3c5ac02b2a4b0324fd0e68aaf4756ae8a35.tar.gz onionshare-89bed3c5ac02b2a4b0324fd0e68aaf4756ae8a35.zip |
If no files are uploaded, delete the empty receive mode dir that was created
-rw-r--r-- | cli/onionshare_cli/web/receive_mode.py | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/cli/onionshare_cli/web/receive_mode.py b/cli/onionshare_cli/web/receive_mode.py index 79d58486..bdbe0a5f 100644 --- a/cli/onionshare_cli/web/receive_mode.py +++ b/cli/onionshare_cli/web/receive_mode.py @@ -536,27 +536,35 @@ class ReceiveModeRequest(Request): if self.upload_request: self.web.common.log("ReceiveModeRequest", "close") - try: - if self.told_gui_about_request: - history_id = self.history_id - - if ( - not self.web.stop_q.empty() - or not self.progress[self.filename]["complete"] - ): - # Inform the GUI that the upload has canceled - self.web.add_request( - self.web.REQUEST_UPLOAD_CANCELED, self.path, {"id": history_id} - ) - else: - # Inform the GUI that the upload has finished - self.web.add_request( - self.web.REQUEST_UPLOAD_FINISHED, self.path, {"id": history_id} - ) - self.web.receive_mode.uploads_in_progress.remove(history_id) + try: + if self.told_gui_about_request: + history_id = self.history_id + + if ( + not self.web.stop_q.empty() + or not self.progress[self.filename]["complete"] + ): + # Inform the GUI that the upload has canceled + self.web.add_request( + self.web.REQUEST_UPLOAD_CANCELED, + self.path, + {"id": history_id}, + ) + else: + # Inform the GUI that the upload has finished + self.web.add_request( + self.web.REQUEST_UPLOAD_FINISHED, + self.path, + {"id": history_id}, + ) + self.web.receive_mode.uploads_in_progress.remove(history_id) + + except AttributeError: + pass - except AttributeError: - pass + # If no files were written to self.receive_mode_dir, delete it + if len(os.listdir(self.receive_mode_dir)) == 0: + os.rmdir(self.receive_mode_dir) def file_write_func(self, filename, length): """ |