From d959ed016cf98afe12ee1333e5571f6eab84f951 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Jan 2016 12:13:43 +0100 Subject: [PATCH] common: Add xdg_app_list_extensions util --- common/xdg-app-utils.c | 90 ++++++++++++++++++++++++++++++++++++++++++ common/xdg-app-utils.h | 13 ++++++ 2 files changed, 103 insertions(+) diff --git a/common/xdg-app-utils.c b/common/xdg-app-utils.c index 4816aaff9..d896f35f4 100644 --- a/common/xdg-app-utils.c +++ b/common/xdg-app-utils.c @@ -1526,3 +1526,93 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo, ostree_repo_abort_transaction (repo, cancellable, NULL); return FALSE; } + +void +xdg_app_extension_free (XdgAppExtension *extension) +{ + g_free (extension->id); + g_free (extension->installed_id); + g_free (extension->ref); + g_free (extension->directory); + g_free (extension); +} + +static XdgAppExtension * +xdg_app_extension_new (const char *id, + const char *extension, + const char *arch, + const char *branch, + const char *directory) +{ + XdgAppExtension *ext = g_new0 (XdgAppExtension, 1); + + ext->id = g_strdup (id); + ext->installed_id = g_strdup (extension); + ext->ref = g_build_filename ("runtime", extension, arch, branch, NULL); + ext->directory = g_strdup (directory); + return ext; +} + +GList * +xdg_app_list_extensions (GKeyFile *metakey, + const char *arch, + const char *default_branch) +{ + g_auto(GStrv) groups = NULL; + g_auto(GStrv) parts = NULL; + int i; + GList *res; + + res = NULL; + + if (arch == NULL) + arch = xdg_app_get_arch (); + + groups = g_key_file_get_groups (metakey, NULL); + for (i = 0; groups[i] != NULL; i++) + { + XdgAppExtension *ext; + char *extension; + + if (g_str_has_prefix (groups[i], "Extension ") && + *(extension = (groups[i] + strlen ("Extension "))) != 0) + { + g_autofree char *directory = g_key_file_get_string (metakey, groups[i], "directory", NULL); + g_autofree char *version = g_key_file_get_string (metakey, groups[i], "version", NULL); + const char *branch; + + if (directory == NULL) + continue; + + if (version) + branch = version; + else + branch = default_branch; + + if (g_key_file_get_boolean (metakey, groups[i], + "subdirectories", NULL)) + { + g_autofree char *prefix = g_strconcat (extension, ".", NULL); + g_auto(GStrv) refs = NULL; + int j; + + refs = xdg_app_list_deployed_refs ("runtime", prefix, arch, branch, + NULL, NULL); + for (j = 0; refs != NULL && refs[j] != NULL; j++) + { + g_autofree char *extended_dir = g_build_filename (directory, refs[j] + strlen (prefix), NULL); + + ext = xdg_app_extension_new (extension, refs[j], arch, branch, extended_dir); + res = g_list_prepend (res, ext); + } + } + else + { + ext = xdg_app_extension_new (extension, extension, arch, branch, directory); + res = g_list_prepend (res, ext); + } + } + } + + return res; +} diff --git a/common/xdg-app-utils.h b/common/xdg-app-utils.h index 25c2760ce..f5c8b3453 100644 --- a/common/xdg-app-utils.h +++ b/common/xdg-app-utils.h @@ -184,6 +184,19 @@ gboolean xdg_app_repo_generate_appstream (OstreeRepo *repo, GCancellable *cancellable, GError **error); +typedef struct { + char *id; + char *installed_id; + char *ref; + char *directory; +} XdgAppExtension; + +void xdg_app_extension_free (XdgAppExtension *extension); + +GList *xdg_app_list_extensions (GKeyFile *metakey, + const char *arch, + const char *branch); + gboolean xdg_app_spawn (GFile *dir, char **output, GError **error,