From 4a5b5c496f79ae0283c0ca31cd1c041977b2474c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 2 Aug 2016 14:08:28 +0200 Subject: [PATCH] Fix using a relative path with --basedir --- CHANGELOG.asciidoc | 2 ++ qutebrowser/utils/standarddir.py | 2 +- tests/unit/utils/test_standarddir.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c3eb5a0ec..1320b659c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -44,6 +44,8 @@ Fixed - When hinting input fields (`:t`), also consider input elements without a type. - Fixed crash when opening an invalid URL with a percent-encoded and a real @ in it - Fixed default `;o` and `;O` bindings +- Fixed local storage not working (and possible other bugs) when using a + relative path with `--basedir`. v0.8.1 ------ diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index 04c4c82a6..10929f251 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -168,7 +168,7 @@ def _from_args(typ, args): suffix = basedir_suffix[typ] except KeyError: # pragma: no cover return (False, None) - return (True, os.path.join(basedir, suffix)) + return (True, os.path.abspath(os.path.join(basedir, suffix))) try: argname = typ_to_argparse_arg[typ] diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index a04797258..de8d175bd 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -225,6 +225,15 @@ class TestArguments: func = getattr(standarddir, typ) assert func() == expected + def test_basedir_relative(self, tmpdir): + """Test --basedir with a relative path.""" + basedir = (tmpdir / 'basedir') + basedir.ensure(dir=True) + with tmpdir.as_cwd(): + args = types.SimpleNamespace(basedir='basedir') + standarddir.init(args) + assert standarddir.config() == str(basedir / 'config') + class TestInitCacheDirTag: @@ -311,6 +320,7 @@ class TestCreatingDir: m.sep = os.sep m.path.join = os.path.join m.path.exists.return_value = False + m.path.abspath = lambda x: x args = types.SimpleNamespace(basedir=str(tmpdir)) standarddir.init(args)