From 8a0aa0e244fa565b8c55aab38cc5e84323c3b481 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 3 Jun 2025 12:43:44 +0200 Subject: [PATCH] fix(standardpaths): Continue to work with xdg, while `--basedir` is set This can be used to simulate firefox's profiles feature (i.e., completely separated data/runtime/cache dirs), while still keeping to the xdg basedir standard. --- qutebrowser/utils/standarddir.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index b82845a96..61319daed 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -285,12 +285,11 @@ def _from_args( The overridden path, or None if there is no override. """ basedir_suffix = { - QStandardPaths.StandardLocation.ConfigLocation: 'config', - QStandardPaths.StandardLocation.AppDataLocation: 'data', - QStandardPaths.StandardLocation.AppLocalDataLocation: 'data', - QStandardPaths.StandardLocation.CacheLocation: 'cache', - QStandardPaths.StandardLocation.DownloadLocation: 'download', - QStandardPaths.StandardLocation.RuntimeLocation: 'runtime', + QStandardPaths.StandardLocation.ConfigLocation: ('config', False), + QStandardPaths.StandardLocation.AppDataLocation: ('data', False), + QStandardPaths.StandardLocation.AppLocalDataLocation: ('data', False), + QStandardPaths.StandardLocation.CacheLocation: ('cache', True), + QStandardPaths.StandardLocation.RuntimeLocation: ('runtime', True), } if getattr(args, 'basedir', None) is None: @@ -298,10 +297,14 @@ def _from_args( assert args is not None try: - suffix = basedir_suffix[typ] + (suffix, extend) = basedir_suffix[typ] except KeyError: # pragma: no cover return None - return os.path.abspath(os.path.join(args.basedir, suffix)) + + if extend: + return os.path.abspath(os.path.join(_writable_location(typ), os.path.basename(args.basedir))) + else: + return os.path.abspath(os.path.join(args.basedir, suffix)) def _create(path: str) -> None: -- 2.49.0