From 1f77af15cb2964608181ba2cb457fc5f24cc334f Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 22 May 2017 11:13:09 +0200 Subject: [PATCH] common: Add flatpak_context_load_for_app helper This looks for an installed app, using the current one, and loads its permissions and overriders (ignoring the ones from the runtime). This is useful if you want to know the permissions for an application by name, such as in the document portal. --- common/flatpak-run.c | 29 +++++++++++++++++++++++++++++ common/flatpak-run.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/common/flatpak-run.c b/common/flatpak-run.c index 27b0255c..8162beb5 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -4520,6 +4520,35 @@ add_rest_args (const char *app_id, return TRUE; } +FlatpakContext * +flatpak_context_load_for_app (const char *app_id, + GError **error) +{ + g_autofree char *app_ref = NULL; + g_autoptr(FlatpakContext) app_context = NULL; + g_autoptr(FlatpakDeploy) app_deploy = NULL; + g_autoptr(FlatpakContext) overrides = NULL; + g_autoptr(GKeyFile) metakey = NULL; + + app_ref = flatpak_find_current_ref (app_id, NULL, error); + if (app_ref == NULL) + return NULL; + + app_deploy = flatpak_find_deploy_for_ref (app_ref, NULL, error); + if (app_deploy == NULL) + return NULL; + + metakey = flatpak_deploy_get_metadata (app_deploy); + app_context = flatpak_app_compute_permissions (metakey, NULL, error); + if (app_context == NULL) + return NULL; + + overrides = flatpak_deploy_get_overrides (app_deploy); + flatpak_context_merge (app_context, overrides); + + return g_steal_pointer (&app_context); +} + gboolean flatpak_run_app (const char *app_ref, FlatpakDeploy *app_deploy, diff --git a/common/flatpak-run.h b/common/flatpak-run.h index 65948857..608c6ee0 100644 --- a/common/flatpak-run.h +++ b/common/flatpak-run.h @@ -71,6 +71,8 @@ void flatpak_context_to_args (FlatpakContext *context, gboolean flatpak_context_get_needs_session_bus_proxy (FlatpakContext *context); gboolean flatpak_context_get_needs_system_bus_proxy (FlatpakContext *context); +FlatpakContext *flatpak_context_load_for_app (const char *app_id, + GError **error); G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakContext, flatpak_context_free)