aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2021-11-09 12:30:48 +1100
committerMiguel Jacq <mig@mig5.net>2021-11-09 12:30:48 +1100
commit096178a9e6133fd6ca9d95a00a67bba75ccab377 (patch)
treee6ad9155a9b61bebe3661ebdd162e577ee5d7352
parent1b259a208d29c2c8e8eae1d2f1fe28e59eed769b (diff)
downloadonionshare-096178a9e6133fd6ca9d95a00a67bba75ccab377.tar.gz
onionshare-096178a9e6133fd6ca9d95a00a67bba75ccab377.zip
Use microseconds for Receive Mode dir/file names
-rw-r--r--cli/onionshare_cli/web/receive_mode.py2
-rw-r--r--desktop/tests/test_gui_receive.py32
2 files changed, 18 insertions, 16 deletions
diff --git a/cli/onionshare_cli/web/receive_mode.py b/cli/onionshare_cli/web/receive_mode.py
index 6b106d37..07964952 100644
--- a/cli/onionshare_cli/web/receive_mode.py
+++ b/cli/onionshare_cli/web/receive_mode.py
@@ -378,7 +378,7 @@ class ReceiveModeRequest(Request):
# Figure out what files should be saved
now = datetime.now()
date_dir = now.strftime("%Y-%m-%d")
- time_dir = now.strftime("%H%M%S")
+ time_dir = now.strftime("%H%M%S%f")
self.receive_mode_dir = os.path.join(
self.web.settings.get("receive", "data_dir"), date_dir, time_dir
)
diff --git a/desktop/tests/test_gui_receive.py b/desktop/tests/test_gui_receive.py
index ca69c957..423b63a0 100644
--- a/desktop/tests/test_gui_receive.py
+++ b/desktop/tests/test_gui_receive.py
@@ -1,3 +1,4 @@
+import glob
import pytest
import os
import requests
@@ -35,17 +36,17 @@ class TestReceive(GuiBaseTest):
now = datetime.now()
for _ in range(10):
date_dir = now.strftime("%Y-%m-%d")
- if identical_files_at_once:
- time_dir = now.strftime("%H%M%S-1")
- else:
- time_dir = now.strftime("%H%M%S")
+ time_dir = now.strftime("%H%M%S")
receive_mode_dir = os.path.join(
tab.settings.get("receive", "data_dir"), date_dir, time_dir
)
- expected_filename = os.path.join(receive_mode_dir, expected_basename)
- if os.path.exists(expected_filename):
- exists = True
- break
+ # The directories have microseconds in the name, so we need
+ # to use globbing against directory names containing the same
+ # second in order to try to find the file.
+ for path in glob.glob(receive_mode_dir + "*"):
+ if os.path.exists(os.path.join(path, expected_basename)):
+ exists = True
+ break
now = now - timedelta(seconds=1)
self.assertTrue(exists)
@@ -83,17 +84,18 @@ class TestReceive(GuiBaseTest):
for _ in range(10):
date_dir = now.strftime("%Y-%m-%d")
time_dir = now.strftime("%H%M%S")
- expected_filename = os.path.join(
+ expected_estimated_filename = os.path.join(
tab.settings.get("receive", "data_dir"),
date_dir,
- f"{time_dir}-message.txt",
+ f"{time_dir}*-message.txt",
)
- if os.path.exists(expected_filename):
- with open(expected_filename) as f:
- assert f.read() == message
+ for path in glob.glob(expected_estimated_filename):
+ if os.path.exists(path):
+ with open(path) as f:
+ assert f.read() == message
- exists = True
- break
+ exists = True
+ break
now = now - timedelta(seconds=1)
self.assertTrue(exists)