diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index d6ad7fc39..c5ee356c0 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -20,6 +20,7 @@ """Utilities to get and initialize data/config paths.""" import os +import sys import shutil import os.path import contextlib @@ -106,6 +107,10 @@ def _init_data(args): if utils.is_windows: app_data_path = _writable_location(QStandardPaths.AppDataLocation) path = os.path.join(app_data_path, 'data') + elif sys.platform.startswith('haiku'): + # HaikuOS returns an empty value for AppDataLocation + config_path = _writable_location(QStandardPaths.ConfigLocation) + path = os.path.join(config_path, 'data') else: path = _writable_location(typ) _create(path) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 20ea88645..1b9e473d1 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -103,6 +103,20 @@ def test_fake_windows(tmpdir, monkeypatch, what): assert func() == str(tmpdir / APPNAME / what) +def test_fake_haiku(tmpdir, monkeypatch): + """Test getting data dir on HaikuOS.""" + locations = { + QStandardPaths.DataLocation: '', + QStandardPaths.ConfigLocation: str(tmpdir / 'config' / APPNAME), + } + monkeypatch.setattr(standarddir.QStandardPaths, 'writableLocation', + locations.get) + monkeypatch.setattr(standarddir.sys, 'platform', 'haiku1') + + standarddir._init_data(args=None) + assert standarddir.data() == str(tmpdir / 'config' / APPNAME / 'data') + + class TestWritableLocation: """Tests for _writable_location."""