From bc892f174527d08aa7a5e0aaa618c773c2d3e601 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Jan 2016 12:33:55 +0100 Subject: [PATCH] run: Use the new xdg_app_list_extensions helper --- common/xdg-app-run.c | 75 +++++++++----------------------------------- 1 file changed, 15 insertions(+), 60 deletions(-) diff --git a/common/xdg-app-run.c b/common/xdg-app-run.c index 4eed256a..eecba6fb 100644 --- a/common/xdg-app-run.c +++ b/common/xdg-app-run.c @@ -1227,33 +1227,6 @@ xdg_app_add_bus_filters (GPtrArray *dbus_proxy_argv, } } -static void -add_extension_arg (const char *directory, - gboolean is_app, - const char *extension, - const char *arch, - const char *branch, - GPtrArray *argv_array, - GCancellable *cancellable) -{ - g_autofree char *extension_ref; - g_autoptr(GFile) deploy = NULL; - g_autofree char *full_directory = NULL; - - - full_directory = g_build_filename (is_app ? "/app" : "/usr", directory, NULL); - - extension_ref = g_build_filename ("runtime", extension, arch, branch, NULL); - deploy = xdg_app_find_deploy_dir_for_ref (extension_ref, cancellable, NULL); - if (deploy != NULL) - { - g_autoptr(GFile) files = g_file_get_child (deploy, "files"); - g_ptr_array_add (argv_array, g_strdup ("-b")); - g_ptr_array_add (argv_array, g_strdup_printf ("%s=%s", full_directory, gs_file_get_path_cached (files))); - } -} - - gboolean xdg_app_run_add_extension_args (GPtrArray *argv_array, GKeyFile *metakey, @@ -1263,8 +1236,8 @@ xdg_app_run_add_extension_args (GPtrArray *argv_array, { g_auto(GStrv) groups = NULL; g_auto(GStrv) parts = NULL; - int i; gboolean is_app; + GList *extensions, *l; parts = g_strsplit (full_ref, "/", 0); if (g_strv_length (parts) != 4) @@ -1272,45 +1245,27 @@ xdg_app_run_add_extension_args (GPtrArray *argv_array, is_app = strcmp (parts[0], "app") == 0; - groups = g_key_file_get_groups (metakey, NULL); - for (i = 0; groups[i] != NULL; i++) + extensions = xdg_app_list_extensions (metakey, + parts[2], parts[3]); + + for (l = extensions; l != NULL; l = l->next) { - char *extension; + XdgAppExtension *ext = l->data; + g_autoptr(GFile) deploy = NULL; - if (g_str_has_prefix (groups[i], "Extension ") && - *(extension = (groups[i] + strlen ("Extension "))) != 0) + deploy = xdg_app_find_deploy_dir_for_ref (ext->ref, cancellable, NULL); + if (deploy != NULL) { - 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); + g_autoptr(GFile) files = g_file_get_child (deploy, "files"); + g_autofree char *full_directory = g_build_filename (is_app ? "/app" : "/usr", ext->directory, NULL); - if (directory == NULL) - continue; - - 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 i; - - refs = xdg_app_list_deployed_refs ("runtime", prefix, parts[2], parts[3], - cancellable, error); - if (refs == NULL) - return FALSE; - - for (i = 0; refs[i] != NULL; i++) - { - g_autofree char *extended_dir = g_build_filename (directory, refs[i] + strlen (prefix), NULL); - add_extension_arg (extended_dir, is_app, refs[i], parts[2], parts[3], - argv_array, cancellable); - } - } - else - add_extension_arg (directory, is_app, extension, parts[2], version ? version : parts[3], - argv_array, cancellable); + g_ptr_array_add (argv_array, g_strdup ("-b")); + g_ptr_array_add (argv_array, g_strdup_printf ("%s=%s", full_directory, gs_file_get_path_cached (files))); } } + g_list_free_full (extensions, (GDestroyNotify)xdg_app_extension_free); + return TRUE; }