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
This commit is contained in:
Jack Pearson 2023-03-09 02:23:58 -08:00 committed by GitHub
parent a32c7a8e63
commit 7fbff43a58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -113,6 +113,7 @@ Mani <github.com/krmanik>
Kaben Nanlohy <kaben.nanlohy@gmail.com> Kaben Nanlohy <kaben.nanlohy@gmail.com>
Tobias Predel <tobias.predel@gmail.com> Tobias Predel <tobias.predel@gmail.com>
Daniel Tang <danielzgtg.opensource@gmail.com> Daniel Tang <danielzgtg.opensource@gmail.com>
Jack Pearson <github.com/jrpear>
******************** ********************

View file

@ -638,6 +638,23 @@ def getFile(
return ret[0] if ret else None 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( def getSaveFile(
parent: QDialog, parent: QDialog,
title: str, title: str,
@ -662,7 +679,7 @@ def getSaveFile(
f"{key} (*{ext})", f"{key} (*{ext})",
options=QFileDialog.Option.DontConfirmOverwrite, options=QFileDialog.Option.DontConfirmOverwrite,
)[0] )[0]
if file: if file and not running_in_sandbox():
# add extension # add extension
if not file.lower().endswith(ext): if not file.lower().endswith(ext):
file += ext file += ext