Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions electrum/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,18 @@ def update_recently_opened_wallets(self, wallet_path, *, remove: bool = False):
recent = recent[:5]
self.config.RECENTLY_OPEN_WALLET_FILES = recent
util.trigger_callback('recently_opened_wallets_update')


def check_fs_permissions(config: 'SimpleConfig'):
Copy link

Choose a reason for hiding this comment

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

This is the only function below the classes, while other generic functions such as this one lives in the beginning of the file. Maybe it could be moved there to keep the file organized that way.

electrum_path = config.electrum_path()
if not os.access(electrum_path, os.R_OK | os.W_OK):
raise Exception('can not read/write root folder at ' + electrum_path)
Copy link

@zrawsig zrawsig Oct 1, 2025

Choose a reason for hiding this comment

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

"can not" is grammatically incorrect, please change to "Cannot". See the factored out example above.

for f in ['config', 'blockchain_headers', 'recent_servers']:
fpath = os.path.join(electrum_path, f)
if os.path.exists(fpath):
if not os.access(fpath, os.R_OK | os.W_OK):
Copy link

Choose a reason for hiding this comment

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

The os.access() check is repeated a few times with the exception message.
This could be factored out to improve readability, for example:

def check_permissions(path: str):
    if not os.access(path, os.R_OK | os.W_OK):
        raise Exception(f'Cannot read/write {path}')

raise Exception(f'can not read/write {f} file at ' + electrum_path)
fpath = os.path.join(electrum_path, 'wallets')
if not os.access(fpath, os.R_OK | os.W_OK):
raise Exception('can not read/write wallet folder at ' + fpath)

9 changes: 9 additions & 0 deletions electrum/gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
os.environ.setdefault("QT_QPA_PLATFORM", "xcb")

from electrum.i18n import _, set_language
from electrum.daemon import check_fs_permissions
from electrum.plugin import run_hook
from electrum.util import (UserCancelled, profiler, send_exception_to_crash_reporter,
WalletFileException, get_new_wallet_name, InvalidPassword,
Expand Down Expand Up @@ -571,6 +572,14 @@ def main(self):
signal.signal(signal.SIGINT, lambda *args: self.app.quit())
# hook for crash reporter
Exception_Hook.maybe_setup(config=self.config)

# check filesystem
try:
check_fs_permissions(self.daemon.config)
except Exception as e:
custom_message_box(icon=QMessageBox.Icon.Critical, parent=None, title=_('filesystem error'), text=str(e))
raise

# start network, and maybe show first-start network-setup
try:
self.ask_terms_of_use()
Expand Down
3 changes: 3 additions & 0 deletions run_electrum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import os
import sys

from electrum.daemon import check_fs_permissions

MIN_PYTHON_VERSION = "3.10.0" # FIXME duplicated from setup.py
_min_python_version_tuple = tuple(map(int, (MIN_PYTHON_VERSION.split("."))))
Expand Down Expand Up @@ -528,6 +529,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
if fd is not None:
# run daemon
d = daemon.Daemon(config, fd)
check_fs_permissions(config)
d.run_daemon()
sys_exit(0)
else:
Expand Down Expand Up @@ -570,6 +572,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
_logger.exception("error running command (with daemon)")
sys_exit(1)
else:
check_fs_permissions(config)
if cmd.requires_network:
print_msg("This command cannot be run offline")
sys_exit(1)
Expand Down