Rename version.is_sandboxed() to is_flatpak()

This commit is contained in:
Florian Bruhin 2021-03-18 10:58:04 +01:00
parent fb0154ae26
commit 5ce8a9c9c1
5 changed files with 14 additions and 7 deletions

View File

@ -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:

View File

@ -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'])

View File

@ -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

View File

@ -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

View File

@ -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: