diff options
author | Micah Lee <micah@micahflee.com> | 2019-03-22 17:50:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-22 17:50:33 -0700 |
commit | a9f3accf69e1560404433137dd2d84433171170d (patch) | |
tree | 6ad1662830ebe1efe29e3693daebee54cf155200 | |
parent | c0e6137294e99e882d119fb3cb10f92e6c7f2c3c (diff) | |
parent | 04fd65de11209e201fa39638b978c30198fc8553 (diff) | |
download | onionshare-a9f3accf69e1560404433137dd2d84433171170d.tar.gz onionshare-a9f3accf69e1560404433137dd2d84433171170d.zip |
Merge pull request #935 from mig5/fix_receive_mode_folder_collision
On a folder name collision, make sure we update the self.receive_mode_dir attribute
-rw-r--r-- | onionshare/web/receive_mode.py | 1 | ||||
-rw-r--r-- | tests/GuiReceiveTest.py | 13 |
2 files changed, 12 insertions, 2 deletions
diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index 25d7aa1b..dcf69a96 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -299,6 +299,7 @@ class ReceiveModeRequest(Request): new_receive_mode_dir = '{}-{}'.format(self.receive_mode_dir, i) try: os.makedirs(new_receive_mode_dir, 0o700, exist_ok=False) + self.receive_mode_dir = new_receive_mode_dir break except OSError: pass diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index fd0c9810..d1581c8e 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -5,7 +5,7 @@ from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiReceiveTest(GuiBaseTest): - def upload_file(self, public_mode, file_to_upload, expected_basename): + def upload_file(self, public_mode, file_to_upload, expected_basename, identical_files_at_once=False): '''Test that we can upload the file''' files = {'file[]': open(file_to_upload, 'rb')} if not public_mode: @@ -13,6 +13,9 @@ class GuiReceiveTest(GuiBaseTest): else: path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) response = requests.post(path, files=files) + if identical_files_at_once: + # Send a duplicate upload to test for collisions + response = requests.post(path, files=files) QtTest.QTest.qWait(2000) # Make sure the file is within the last 10 seconds worth of filenames @@ -20,7 +23,10 @@ class GuiReceiveTest(GuiBaseTest): now = datetime.now() for i in range(10): date_dir = now.strftime("%Y-%m-%d") - time_dir = now.strftime("%H.%M.%S") + if identical_files_at_once: + time_dir = now.strftime("%H.%M.%S-1") + else: + time_dir = now.strftime("%H.%M.%S") receive_mode_dir = os.path.join(self.gui.common.settings.get('data_dir'), date_dir, time_dir) expected_filename = os.path.join(receive_mode_dir, expected_basename) if os.path.exists(expected_filename): @@ -107,6 +113,9 @@ class GuiReceiveTest(GuiBaseTest): self.counter_incremented(self.gui.receive_mode, 3) self.upload_file(public_mode, '/tmp/testdir/test', 'test') self.counter_incremented(self.gui.receive_mode, 4) + # Test uploading the same file twice at the same time, and make sure no collisions + self.upload_file(public_mode, '/tmp/test.txt', 'test.txt', True) + self.counter_incremented(self.gui.receive_mode, 6) self.uploading_zero_files_shouldnt_change_ui(self.gui.receive_mode, public_mode) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) |