Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
8 changes: 7 additions & 1 deletion src/maestral/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
APP_NAME = "Maestral"
BUNDLE_ID = "com.samschott.maestral"
APP_ICON_PATH = path("maestral.resources", "maestral.png").__enter__()
ENV = {"PYTHONOPTIMIZE": "2", "LC_CTYPE": "UTF-8"}

if platform.system == "OpenBSD":
Copy link
Owner

Choose a reason for hiding this comment

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

Note the missing brackets in the function call. I think you want platform.system() == "OpenBSD" here instead. This should clear up the strange behaviour.

#ENV = {"PYTHONOPTIMIZE": "2", "LC_CTYPE": "C.UTF-8"}
ENV = {}
else:
ENV = {"PYTHONOPTIMIZE": "2", "LC_CTYPE": "UTF-8"}
Copy link
Owner

Choose a reason for hiding this comment

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

According to OpenBSD man pages, switching to LC_CTYPE=C.UTF-8 should do the trick. This should also be compatible with other platforms so we won't need a special case for OpenBSD.


# sync
OLD_REV_FILE = ".maestral"
Expand Down Expand Up @@ -69,6 +74,7 @@ class FileStatus(Enum):
# platform detection
IS_MACOS = platform.system() == "Darwin"
IS_LINUX = platform.system() == "Linux"
IS_OPENBSD = platform.system() == "OpenBSD"

# keys
DROPBOX_APP_KEY = "2jmbq42w7vof78h"
Expand Down
11 changes: 9 additions & 2 deletions src/maestral/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# local imports
from .utils import exc_info_tuple
from .utils.appdirs import get_runtime_path
from .constants import IS_MACOS, ENV
from .constants import IS_MACOS, IS_OPENBSD, ENV
from . import core, models, exceptions


Expand Down Expand Up @@ -253,6 +253,10 @@ def locking_pid(self) -> int | None:
fmt = "qqihh"
pid_index = 2
flock = struct.pack(fmt, 0, 0, 0, fcntl.F_WRLCK, 0)
elif IS_OPENBSD:
fmt = "qqihh"
pid_index = 2
flock = struct.pack(fmt, 0, 0, 0, fcntl.F_WRLCK, 0)
Copy link
Owner

@samschott samschott Jun 14, 2022

Choose a reason for hiding this comment

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

Am I missing something or this exactly the same as on macOS (which is BSD-based)? If yes, let's just have a single IS_MACOS or IS_BSD check.

else:
fmt = "hhqqih"
pid_index = 4
Expand Down Expand Up @@ -540,7 +544,10 @@ def start_maestral_daemon_process(
script = f'import maestral.daemon; maestral.daemon.start_maestral_daemon("{cc}")'

env = os.environ.copy()
env.update(ENV)
# Don't copy the environment on OpenBSD because it makes the daemon want
# everything in ASCII.
if not IS_OPENBSD:
env.update(ENV)

pid = os.spawnve(os.P_NOWAIT, sys.executable, [sys.executable, "-c", script], env)

Expand Down
12 changes: 6 additions & 6 deletions src/maestral/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_conf_path(
"""
if platform.system() == "Darwin":
conf_path = osp.join(get_home_dir(), "Library", "Application Support")
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
fallback = osp.join(get_home_dir(), ".config")
conf_path = os.environ.get("XDG_CONFIG_HOME", fallback)
else:
Expand Down Expand Up @@ -99,7 +99,7 @@ def get_data_path(
"""
if platform.system() == "Darwin":
state_path = osp.join(get_home_dir(), "Library", "Application Support")
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
fallback = osp.join(get_home_dir(), ".local", "share")
state_path = os.environ.get("XDG_DATA_HOME", fallback)
else:
Expand All @@ -124,7 +124,7 @@ def get_cache_path(
"""
if platform.system() == "Darwin":
cache_path = osp.join(home_dir, "Library", "Caches")
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
fallback = osp.join(home_dir, ".cache")
cache_path = os.environ.get("XDG_CACHE_HOME", fallback)
else:
Expand All @@ -150,7 +150,7 @@ def get_log_path(

if platform.system() == "Darwin":
log_path = osp.join(home_dir, "Library", "Logs")
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
log_path = get_cache_path(create=False)
else:
raise RuntimeError("Platform not supported")
Expand All @@ -171,7 +171,7 @@ def get_autostart_path(filename: Optional[str] = None, create: bool = True) -> s
"""
if platform.system() == "Darwin":
autostart_path = osp.join(home_dir, "Library", "LaunchAgents")
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
autostart_path = get_conf_path("autostart", create=create)
else:
raise RuntimeError("Platform not supported")
Expand Down Expand Up @@ -199,7 +199,7 @@ def get_runtime_path(

if platform.system() == "Darwin":
runtime_path = get_conf_path(create=False)
elif platform.system() == "Linux":
elif platform.system() == "Linux" or platform.system() == "OpenBSD":
fallback = get_cache_path(create=False)
runtime_path = os.environ.get("XDG_RUNTIME_DIR", fallback)
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/offline/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import platform
import pytest

from click.testing import CliRunner

Expand Down Expand Up @@ -111,7 +113,12 @@ def test_filestatus(m: Maestral) -> None:
assert "'/invalid-dir' does not exist" in result.output


@pytest.mark.skipif(
platform.system() == "OpenBSD",
reason="OpenBSD doesn't have an autostart mechanism (beyond the .xsession file)",
)
def test_autostart(m: Maestral) -> None:

autostart = AutoStart(m.config_name)
autostart.disable()

Expand Down