From 5ce8a9c9c19e2aaec591b191d3c3efebd1957fa7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 18 Mar 2021 10:58:04 +0100 Subject: Rename version.is_sandboxed() to is_flatpak() --- qutebrowser/misc/elf.py | 2 +- qutebrowser/utils/standarddir.py | 5 ++++- qutebrowser/utils/utils.py | 2 +- qutebrowser/utils/version.py | 8 ++++++-- tests/unit/utils/test_version.py | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/qutebrowser/misc/elf.py b/qutebrowser/misc/elf.py index 6d35eecb4..18cb9634c 100644 --- a/qutebrowser/misc/elf.py +++ b/qutebrowser/misc/elf.py @@ -310,7 +310,7 @@ def _parse_from_file(f: IO[bytes]) -> Versions: def parse_webenginecore() -> Optional[Versions]: """Parse the QtWebEngineCore library file.""" - if version.is_sandboxed(): + if version.is_flatpak(): # Flatpak has Qt in /usr/lib/x86_64-linux-gnu, but QtWebEngine in /app/lib. library_path = pathlib.Path("/app/lib") else: diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index 4ea7e5dbf..7bb632b57 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -232,7 +232,10 @@ def _init_runtime(args: Optional[argparse.Namespace]) -> None: # Unfortunately this path could get too long for sockets (which have a # maximum length of 104 chars), so we don't add the username here... - if version.is_sandboxed(): + if version.is_flatpak(): + # We need a path like /run/user/1000/app/org.qutebrowser.qutebrowser rather than + # /run/user/1000/qutebrowser on Flatpak, since that's bind-mounted in a way that + # it is accessible by any other qutebrowser instances. *parts, app_name = os.path.split(path) assert app_name == APPNAME, app_name path = os.path.join(*parts, 'app', os.environ['FLATPAK_ID']) diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index afc4c4f8d..2a47d60aa 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -605,7 +605,7 @@ def open_file(filename: str, cmdline: str = None) -> None: # if we want to use the default override = config.val.downloads.open_dispatcher - if version.is_sandboxed(): + if version.is_flatpak(): if cmdline: message.error("Cannot spawn download dispatcher from sandbox") return diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 63097bb8b..89da353fc 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -183,8 +183,12 @@ def distribution() -> Optional[DistributionInfo]: parsed=parsed, version=dist_version, pretty=pretty, id=dist_id) -def is_sandboxed() -> bool: - """Whether the environment has restricted access to the host system.""" +def is_flatpak() -> bool: + """Whether qutebrowser is running via Flatpak. + + If packaged via Flatpak, the environment is has restricted access to the host + system. + """ current_distro = distribution() if current_distro is None: return False diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index 4b01be537..a53b4bdce 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -319,9 +319,9 @@ def test_distribution(tmpdir, monkeypatch, os_release, expected): id='arch', parsed=version.Distribution.arch, version=None, pretty='Arch Linux'), False) ]) -def test_is_sandboxed(monkeypatch, distribution, expected): +def test_is_flatpak(monkeypatch, distribution, expected): monkeypatch.setattr(version, "distribution", lambda: distribution) - assert version.is_sandboxed() == expected + assert version.is_flatpak() == expected class GitStrSubprocessFake: -- cgit v1.2.3-54-g00ecf