From d3dd2d6f7fcc634532034558e9938361d5e96b20 Mon Sep 17 00:00:00 2001 From: Martin Abente Lahaye Date: Thu, 31 Aug 2023 11:31:30 -0400 Subject: [PATCH] permissions: Gracefully handle malformed override files Override files aren't owned by Flatseal, therefore there's no guarantees on its contents. Closes #558 --- src/models/permissions.js | 18 +++++++++++++----- src/widgets/window.js | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/models/permissions.js b/src/models/permissions.js index 75e559ab..09fe987d 100644 --- a/src/models/permissions.js +++ b/src/models/permissions.js @@ -93,6 +93,7 @@ var FlatpakPermissionsModel = GObject.registerClass({ param_types: [GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN], }, reset: {}, + failed: {}, }, }, class FlatpakPermissionsModel extends GObject.Object { _init() { @@ -122,12 +123,19 @@ var FlatpakPermissionsModel = GObject.registerClass({ return GLib.build_filenamev([this._getBaseOverridesPath(), this._appId]); } - static _loadPermissionsForPath(path, overrides, global) { + _loadPermissionsForPath(path, overrides, global) { if (GLib.access(path, 0) !== 0) return; const keyFile = new GLib.KeyFile(); - keyFile.load_from_file(path, 0); + + try { + keyFile.load_from_file(path, 0); + } catch (err) { + logError(err, `Could not load ${path}`); + this.emit('failed'); + return; + } const [groups] = keyFile.get_groups(); @@ -178,7 +186,7 @@ var FlatpakPermissionsModel = GObject.registerClass({ if (isGlobalOverride(this._appId)) return; - this.constructor._loadPermissionsForPath( + this._loadPermissionsForPath( this._applications.getMetadataPathForAppId(this._appId), false, false); } @@ -186,12 +194,12 @@ var FlatpakPermissionsModel = GObject.registerClass({ if (isGlobalOverride(this._appId)) return; - this.constructor._loadPermissionsForPath( + this._loadPermissionsForPath( this._getGlobalOverridesPath(), true, true); } _loadOverrides() { - this.constructor._loadPermissionsForPath( + this._loadPermissionsForPath( this._getOverridesPath(), true, false); } diff --git a/src/widgets/window.js b/src/widgets/window.js index 6b634cab..d3b37283 100644 --- a/src/widgets/window.js +++ b/src/widgets/window.js @@ -106,6 +106,13 @@ var FlatsealWindow = GObject.registerClass({ this._toast.connect('button-clicked', this._undoReset.bind(this)); this._permissions.connect('reset', this._showToast.bind(this)); + this._failedToast = new Adw.Toast(); + this._failedToast.title = _('Could not load overrides'); + this._failedToast.button_label = _('_Reset'); + this._failedToast.timeout = null; + this._failedToast.connect('button-clicked', this._doReset.bind(this)); + this._permissions.connect('failed', this._showFailedToast.bind(this)); + this._contentLeaflet.bind_property( 'folded', this._backButton, 'visible', _bindReadFlags); @@ -275,6 +282,7 @@ var FlatsealWindow = GObject.registerClass({ } _updatePermissions() { + this._failedToast.dismiss(); const row = this._applicationsListBox.get_selected_row(); this._permissions.appId = row.appId; this._permissionsTitle.title = row.appName; @@ -339,6 +347,14 @@ var FlatsealWindow = GObject.registerClass({ this._toastOverlay.add_toast(this._toast); } + _showFailedToast() { + this._toastOverlay.add_toast(this._failedToast); + } + + _doReset() { + this._permissions.reset(); + } + _undoReset() { this._permissions.undo(); }