From 7fbff43a58ce236d8b0172e353dee7ee4abaf5b1 Mon Sep 17 00:00:00 2001 From: Jack Pearson Date: Thu, 9 Mar 2023 02:23:58 -0800 Subject: [PATCH] Fix silent file save failures and bad default save path in Flatpak (#2427) * add Jack Pearson to CONTRIBUTORS * Skip file cleanup operations when impossible in sandbox * Rename checkNeedPortalSupport -> running_in_sandbox --- CONTRIBUTORS | 1 + qt/aqt/utils.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2c01107dc..6beb22cfa 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -113,6 +113,7 @@ Mani Kaben Nanlohy Tobias Predel Daniel Tang +Jack Pearson ******************** diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index bbbde1382..b594d52d2 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -638,6 +638,23 @@ def getFile( return ret[0] if ret else None +def running_in_sandbox(): + """Check whether running in Flatpak or Snap. When in such a sandbox, Qt + will not report the true location of user-chosen files, but instead a + temporary location from which the sandboxing software will copy the file to + the user-chosen destination. Thus file renames are impossible and caching + the reported file location is unhelpful.""" + in_flatpak = ( + QStandardPaths.locate( + QStandardPaths.StandardLocation.RuntimeLocation, + "flatpak-info", + ) + != "" + ) + in_snap = os.environ.get("SNAP") != "" + return in_flatpak or in_snap + + def getSaveFile( parent: QDialog, title: str, @@ -662,7 +679,7 @@ def getSaveFile( f"{key} (*{ext})", options=QFileDialog.Option.DontConfirmOverwrite, )[0] - if file: + if file and not running_in_sandbox(): # add extension if not file.lower().endswith(ext): file += ext