Warn when Receive Mode save folder is not writable by Pitchfork-and-Torch · Pull Request #2090 · onionshare/onionshare · GitHub
Skip to content

Warn when Receive Mode save folder is not writable - #2090

Merged
mig5 merged 3 commits into
onionshare:mainfrom
Pitchfork-and-Torch:fix/receive-warn-unwritable-data-dir
Oct 2, 2026
Merged

mig5 merged 3 commits into
onionshare:mainfrom
Pitchfork-and-Torch:fix/receive-warn-unwritable-data-dir

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown
Contributor

Summary

Fixes #2062.

Receive Mode allowed selecting a non-writable folder (e.g. /root under Tails AppArmor) and starting with no warning. Uploads then failed only when files arrived.

Changes

  • Probe writability with a real create/delete test (better than os.access alone for sandboxes)
  • Reject non-writable folders when browsing
  • Block Start Receive Mode until a writable folder is chosen
  • English string gui_receive_data_dir_not_writable
  • Unit tests for the probe helper

Testing

  • Unit tests for writable dir / missing path / file path
  • Manual GUI check recommended on Linux/Tails if available

Users (including Tails AppArmor sandbox cases) could pick a directory
like /root and start Receive Mode with no error until uploads failed.

Check writability with a real probe on browse and before start, and show
a clear warning. Adds unit tests for the probe helper.

Fixes onionshare#2062.
@Pitchfork-and-Torch

Copy link
Copy Markdown
Contributor Author

@SaptakS

SaptakS commented Jul 27, 2026

Copy link
Copy Markdown
Member

Hello @Pitchfork-and-Torch . Thanks for the PR and your contribution. I am going to review the changes soon but probably won't make it to the 2.6.5 release.

@SaptakS SaptakS added this to the 2.7 milestone Jul 29, 2026
@Pitchfork-and-Torch

Copy link
Copy Markdown
Contributor Author

Thanks @SaptakS. No rush on 2.6.5. Happy to wait for the next train, and I will rebase if main moves before review.

try:
test_path = os.path.join(path, ".onionshare-write-test")
with open(test_path, "w", encoding="utf-8") as f:
f.write("ok")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to make this a named temp file rather than write to a predictable, static file name? (Not that it's likely to contain any real data, but technically, we're overwriting it, so it's just good practice I think).

Something like this (make sure to add import tempfile):

@staticmethod
def is_data_dir_writable(path):
    """Check directory creation, file writing, and cleanup."""
    if not path or not os.path.isdir(path):
        return False

    try:
        with tempfile.TemporaryDirectory(
            prefix=".onionshare-write-test-",
            dir=path,
        ) as probe_dir:
            with tempfile.NamedTemporaryFile(
                mode="wb",
                prefix="probe-",
                dir=probe_dir,
            ) as probe:
                probe.write(b"ok")
                probe.flush()

        return True
    except OSError:
        return False

Comment thread desktop/onionshare/tab/mode/receive_mode/__init__.py
@Pitchfork-and-Torch

Copy link
Copy Markdown
Contributor Author

@mig5
mig5 merged commit 4c3bb1e into onionshare:main Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OnionShare should warn when the user selects a non-writable directory

3 participants