[gnome-software/1722-flatpak-handle-more-well-known-filesystem-permissions] app: Turn update-permissions flags into a GsAppPermissions object



commit 5700cdcbfd3a14182a629cf2204133ee5bcd5844
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 17 10:38:44 2022 +0200

    app: Turn update-permissions flags into a GsAppPermissions object
    
    Modify also related parts, to avoid unbuildable sources.

 lib/gs-app.c                 | 48 +++++++++++++++++++++++++++++++++++++-------
 lib/gs-app.h                 |  6 +++---
 plugins/flatpak/gs-flatpak.c |  3 +--
 src/gs-app-details-page.c    | 36 +++++++++++++++++++++++++++++----
 4 files changed, 77 insertions(+), 16 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index f03a34df6..7b6e08ebd 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -93,7 +93,7 @@ typedef struct
        gchar                   *update_version_ui;
        gchar                   *update_details_markup;
        AsUrgencyKind            update_urgency;
-       GsAppPermissionsFlags    update_permissions;
+       GsAppPermissions        *update_permissions;
        GWeakRef                 management_plugin_weak;  /* (element-type GsPlugin) */
        guint                    match_value;
        guint                    priority;
@@ -5485,6 +5485,7 @@ gs_app_finalize (GObject *object)
        g_clear_object (&priv->local_file);
        g_clear_object (&priv->content_rating);
        g_clear_object (&priv->action_screenshot);
+       g_clear_object (&priv->update_permissions);
 
        G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
 }
@@ -6284,21 +6285,54 @@ gs_app_set_permissions (GsApp *app,
        gs_app_queue_notify (app, obj_props[PROP_PERMISSIONS]);
 }
 
-GsAppPermissionsFlags
-gs_app_get_update_permissions (GsApp *app)
+/**
+ * gs_app_dup_update_permissions:
+ * @app: a #GsApp
+ *
+ * Get a reference to the update permissions. The returned value can
+ * be %NULL, when no update permissions had been set. Free
+ * the returned pointer, if not %NULL, with g_object_unref(), when
+ * no longer needed.
+ *
+ * Returns: (nullable) (transfer full): referenced #GsAppPermissions,
+ *    or %NULL
+ *
+ * Since: 43
+ **/
+GsAppPermissions *
+gs_app_dup_update_permissions (GsApp *app)
 {
        GsAppPrivate *priv = gs_app_get_instance_private (app);
-       g_return_val_if_fail (GS_IS_APP (app), GS_APP_PERMISSIONS_FLAGS_UNKNOWN);
-       return priv->update_permissions;
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       locker = g_mutex_locker_new (&priv->mutex);
+       return priv->update_permissions ? g_object_ref (priv->update_permissions) : NULL;
 }
 
+/**
+ * gs_app_set_update_permissions:
+ * @app: a #GsApp
+ * @update_permissions: (nullable) (transfer none): a #GsAppPermissions, or %NULL
+ *
+ * Set update permissions for the @app, that is, the permissions, which change
+ * in an update or similar reasons. The @update_permissions is referenced,
+ * if not %NULL.
+ *
+ * Since: 43
+ **/
 void
 gs_app_set_update_permissions (GsApp *app,
-                              GsAppPermissionsFlags update_permissions)
+                              GsAppPermissions *update_permissions)
 {
        GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
        g_return_if_fail (GS_IS_APP (app));
-       priv->update_permissions = update_permissions;
+       locker = g_mutex_locker_new (&priv->mutex);
+       if (priv->update_permissions != update_permissions) {
+               g_clear_object (&priv->update_permissions);
+               if (update_permissions != NULL)
+                       priv->update_permissions = g_object_ref (update_permissions);
+       }
 }
 
 /**
diff --git a/lib/gs-app.h b/lib/gs-app.h
index f93903366..56a5ff7bf 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -495,10 +495,10 @@ GsAppPermissionsFlags
                 gs_app_get_permissions         (GsApp          *app);
 void            gs_app_set_permissions         (GsApp          *app,
                                                 GsAppPermissionsFlags permissions);
-GsAppPermissionsFlags
-                gs_app_get_update_permissions  (GsApp          *app);
+GsAppPermissions *
+                gs_app_dup_update_permissions  (GsApp          *app);
 void            gs_app_set_update_permissions  (GsApp          *app,
-                                                GsAppPermissionsFlags update_permissions);
+                                                GsAppPermissions *update_permissions);
 GPtrArray      *gs_app_get_version_history     (GsApp          *app);
 void            gs_app_set_version_history     (GsApp          *app,
                                                 GPtrArray      *version_history);
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index d8bae4d5b..2dd523168 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -500,8 +500,7 @@ gs_flatpak_set_update_permissions (GsFlatpak           *self,
        if (gs_app_permissions_get_flags (permissions) == GS_APP_PERMISSIONS_FLAGS_UNKNOWN)
                gs_app_permissions_set_flags (permissions, GS_APP_PERMISSIONS_FLAGS_NONE);
 
-       /* Use only flags, until the GsApp holds the GsAppPermissions */
-       gs_app_set_update_permissions (app, gs_app_permissions_get_flags (permissions));
+       gs_app_set_update_permissions (app, permissions);
 
        if (gs_app_permissions_get_flags (permissions) != GS_APP_PERMISSIONS_FLAGS_NONE)
                gs_app_add_quirk (app, GS_APP_QUIRK_NEW_PERMISSIONS);
diff --git a/src/gs-app-details-page.c b/src/gs-app-details-page.c
index b210a9703..27a296d98 100644
--- a/src/gs-app-details-page.c
+++ b/src/gs-app-details-page.c
@@ -73,7 +73,7 @@ static const struct {
   { GS_APP_PERMISSIONS_FLAGS_HOME_READ, N_("Home folder"), N_("Can view files") },
   { GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_FULL, N_("File system"), N_("Can view, edit and create files") },
   { GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_READ, N_("File system"), N_("Can view files") },
-  { GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_OTHER, N_("File system"), N_("Can access arbitrary files") },
+  /* The GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_OTHER is used only as a flag, with actual files being part of 
the read/full lists */
   { GS_APP_PERMISSIONS_FLAGS_DOWNLOADS_FULL, N_("Downloads folder"), N_("Can view, edit and create files") },
   { GS_APP_PERMISSIONS_FLAGS_DOWNLOADS_READ, N_("Downloads folder"), N_("Can view files") },
   { GS_APP_PERMISSIONS_FLAGS_SETTINGS, N_("Settings"), N_("Can view and change any settings") },
@@ -104,14 +104,31 @@ add_permissions_row (GsAppDetailsPage *page,
        gtk_list_box_append (GTK_LIST_BOX (page->permissions_section_list), row);
 }
 
+static void
+populate_permissions_filesystem (GsAppDetailsPage *page,
+                                const GPtrArray *titles, /* (element-type utf-8) */
+                                const gchar *subtitle,
+                                gboolean is_warning_row)
+{
+       if (titles == NULL)
+               return;
+
+       for (guint i = 0; i < titles->len; i++) {
+               const gchar *title = g_ptr_array_index (titles, i);
+               add_permissions_row (page, title, subtitle, is_warning_row);
+       }
+}
+
 static void
 populate_permissions_section (GsAppDetailsPage *page,
-                             GsAppPermissionsFlags permissions)
+                             GsAppPermissions *permissions)
 {
+       GsAppPermissionsFlags flags = gs_app_permissions_get_flags (permissions);
+
        gs_widget_remove_all (page->permissions_section_list, (GsRemoveFunc) gtk_list_box_remove);
 
        for (gsize i = 0; i < G_N_ELEMENTS (permission_display_data); i++) {
-               if ((permissions & permission_display_data[i].permission) == 0)
+               if ((flags & permission_display_data[i].permission) == 0)
                        continue;
 
                add_permissions_row (page,
@@ -119,6 +136,16 @@ populate_permissions_section (GsAppDetailsPage *page,
                        _(permission_display_data[i].subtitle),
                        (permission_display_data[i].permission & ~MEDIUM_PERMISSIONS) != 0);
        }
+
+       populate_permissions_filesystem (page,
+               gs_app_permissions_get_filesystem_read (permissions),
+               _("Can view files"),
+               (GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_READ & ~MEDIUM_PERMISSIONS) != 0);
+
+       populate_permissions_filesystem (page,
+               gs_app_permissions_get_filesystem_full (permissions),
+               _("Can view, edit and create files"),
+               (GS_APP_PERMISSIONS_FLAGS_FILESYSTEM_FULL & ~MEDIUM_PERMISSIONS) != 0);
 }
 
 static void
@@ -204,8 +231,9 @@ set_updates_description_ui (GsAppDetailsPage *page, GsApp *app)
        adw_status_page_set_paintable (ADW_STATUS_PAGE (page->status_page), GDK_PAINTABLE (paintable));
 
        if (gs_app_has_quirk (app, GS_APP_QUIRK_NEW_PERMISSIONS)) {
+               g_autoptr(GsAppPermissions) permissions = gs_app_dup_update_permissions (app);
                gtk_widget_show (page->permissions_section);
-               populate_permissions_section (page, gs_app_get_update_permissions (app));
+               populate_permissions_section (page, permissions);
        } else {
                gtk_widget_hide (page->permissions_section);
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]