diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-09-22 13:57:20 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-09-22 13:57:20 +0200 |
commit | 727f50e923881a41c0c0eec39b15f5339c8acf9e (patch) | |
tree | 03caa3a0445800093a0d55497b4a1904b7882c69 | |
parent | 3334c08f6e50b95dba093466907db0890b66ab40 (diff) | |
download | xdg-app-727f50e923881a41c0c0eec39b15f5339c8acf9e.tar.gz |
xdg-app build: Support extensions
-rw-r--r-- | app/xdg-app-builtins-build.c | 35 | ||||
-rw-r--r-- | app/xdg-app-builtins-run.c | 90 | ||||
-rw-r--r-- | lib/xdg-app-run.c | 92 | ||||
-rw-r--r-- | lib/xdg-app-run.h | 5 |
4 files changed, 115 insertions, 107 deletions
diff --git a/app/xdg-app-builtins-build.c b/app/xdg-app-builtins-build.c index 325a724..ed6beb2 100644 --- a/app/xdg-app-builtins-build.c +++ b/app/xdg-app-builtins-build.c @@ -43,8 +43,7 @@ static GOptionEntry options[] = { gboolean xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError **error) { - GOptionContext *context; - gboolean ret = FALSE; + g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDeploy) runtime_deploy = NULL; g_autoptr(GFile) var = NULL; g_autoptr(GFile) app_deploy = NULL; @@ -86,12 +85,12 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError g_option_context_add_group (context, xdg_app_context_get_options (arg_context)); if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) - goto out; + return FALSE; if (rest_argc == 0) { usage_error (context, "DIRECTORY must be specified", error); - goto out; + return FALSE; } directory = argv[rest_argv_start]; @@ -102,31 +101,31 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError metadata = g_file_get_child (app_deploy, "metadata"); if (!g_file_load_contents (metadata, cancellable, &metadata_contents, &metadata_size, NULL, error)) - goto out; + return FALSE; metakey = g_key_file_new (); if (!g_key_file_load_from_data (metakey, metadata_contents, metadata_size, 0, error)) - goto out; + return FALSE; app_id = g_key_file_get_string (metakey, "Application", "name", error); if (app_id == NULL) - goto out; + return FALSE; runtime = g_key_file_get_string (metakey, "Application", opt_runtime ? "runtime" : "sdk", error); if (runtime == NULL) - goto out; + return FALSE; runtime_ref = g_build_filename ("runtime", runtime, NULL); runtime_deploy = xdg_app_find_deploy_for_ref (runtime_ref, cancellable, error); if (runtime_deploy == NULL) - goto out; + return FALSE; runtime_metakey = xdg_app_deploy_get_metadata (runtime_deploy); var = g_file_get_child (app_deploy, "var"); if (!gs_file_ensure_directory (var, TRUE, cancellable, error)) - goto out; + return FALSE; app_files = g_file_get_child (app_deploy, "files"); runtime_files = xdg_app_deploy_get_files (runtime_deploy); @@ -138,9 +137,9 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError app_context = xdg_app_context_new (); if (!xdg_app_context_load_metadata (app_context, runtime_metakey, error)) - goto out; + return FALSE; if (!xdg_app_context_load_metadata (app_context, metakey, error)) - goto out; + return FALSE; xdg_app_context_merge (app_context, arg_context); xdg_app_context_allow_host_fs (app_context); @@ -148,6 +147,9 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError xdg_app_run_add_environment_args (argv_array, NULL, NULL, app_id, app_context, NULL); + if (!xdg_app_run_add_extension_args (argv_array, runtime_metakey, runtime_ref, cancellable, error)) + return FALSE; + g_ptr_array_add (argv_array, g_strdup ("-a")); g_ptr_array_add (argv_array, g_file_get_path (app_files)); g_ptr_array_add (argv_array, g_strdup ("-v")); @@ -166,14 +168,9 @@ xdg_app_builtin_build (int argc, char **argv, GCancellable *cancellable, GError if (!execve (HELPER, (char **)argv_array->pdata, envp)) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Unable to start app"); - goto out; + return FALSE; } /* Not actually reached... */ - ret = TRUE; - - out: - if (context) - g_option_context_free (context); - return ret; + return TRUE; } diff --git a/app/xdg-app-builtins-run.c b/app/xdg-app-builtins-run.c index a5bdea6..07cf7b3 100644 --- a/app/xdg-app-builtins-run.c +++ b/app/xdg-app-builtins-run.c @@ -51,92 +51,6 @@ static GOptionEntry options[] = { }; static void -add_extension_arg (const char *directory, - const char *type, 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; - gboolean is_app; - - is_app = strcmp (type, "app") == 0; - - full_directory = g_build_filename (is_app ? "/app" : "/usr", directory, NULL); - - extension_ref = g_build_filename (type, 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))); - } -} - -static gboolean -add_extension_args (GKeyFile *metakey, const char *full_ref, - GPtrArray *argv_array, GCancellable *cancellable, GError **error) -{ - g_auto(GStrv) groups = NULL; - g_auto(GStrv) parts = NULL; - gboolean ret = FALSE; - int i; - - ret = TRUE; - - parts = g_strsplit (full_ref, "/", 0); - if (g_strv_length (parts) != 4) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to determine parts from ref: %s", full_ref); - goto out; - } - - groups = g_key_file_get_groups (metakey, NULL); - for (i = 0; groups[i] != NULL; i++) - { - 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); - - 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 (parts[0], prefix, parts[2], parts[3], - cancellable, error); - if (refs == NULL) - goto out; - - 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, parts[0], refs[i], parts[2], parts[3], - argv_array, cancellable); - } - } - else - add_extension_arg (directory, parts[0], extension, parts[2], version ? version : parts[3], - argv_array, cancellable); - } - } - - ret = TRUE; - out: - return ret; -} - -static void dbus_spawn_child_setup (gpointer user_data) { int fd = GPOINTER_TO_INT (user_data); @@ -237,7 +151,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError ** g_ptr_array_add (argv_array, g_strdup (HELPER)); g_ptr_array_add (argv_array, g_strdup ("-l")); - if (!add_extension_args (metakey, app_ref, argv_array, cancellable, error)) + if (!xdg_app_run_add_extension_args (argv_array, metakey, app_ref, cancellable, error)) goto out; if (opt_runtime) @@ -268,7 +182,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError ** xdg_app_context_merge (app_context, arg_context); - if (!add_extension_args (runtime_metakey, runtime_ref, argv_array, cancellable, error)) + if (!xdg_app_run_add_extension_args (argv_array, runtime_metakey, runtime_ref, cancellable, error)) goto out; if ((app_id_dir = xdg_app_ensure_data_dir (app, cancellable, error)) == NULL) diff --git a/lib/xdg-app-run.c b/lib/xdg-app-run.c index 92f3522..76f1251 100644 --- a/lib/xdg-app-run.c +++ b/lib/xdg-app-run.c @@ -1120,6 +1120,98 @@ xdg_app_add_bus_filters (GPtrArray *dbus_proxy_argv, } } +static void +add_extension_arg (const char *directory, + const char *type, + 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; + gboolean is_app; + + is_app = strcmp (type, "app") == 0; + + full_directory = g_build_filename (is_app ? "/app" : "/usr", directory, NULL); + + extension_ref = g_build_filename (type, 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, + const char *full_ref, + GCancellable *cancellable, + GError **error) +{ + g_auto(GStrv) groups = NULL; + g_auto(GStrv) parts = NULL; + gboolean ret = FALSE; + int i; + + ret = TRUE; + + parts = g_strsplit (full_ref, "/", 0); + if (g_strv_length (parts) != 4) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to determine parts from ref: %s", full_ref); + return FALSE; + } + + groups = g_key_file_get_groups (metakey, NULL); + for (i = 0; groups[i] != NULL; i++) + { + 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); + + 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 (parts[0], 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, parts[0], refs[i], parts[2], parts[3], + argv_array, cancellable); + } + } + else + add_extension_arg (directory, parts[0], extension, parts[2], version ? version : parts[3], + argv_array, cancellable); + } + } + + return TRUE; +} + void xdg_app_run_add_environment_args (GPtrArray *argv_array, GPtrArray *dbus_proxy_argv, diff --git a/lib/xdg-app-run.h b/lib/xdg-app-run.h index 28b44b4..472a62e 100644 --- a/lib/xdg-app-run.h +++ b/lib/xdg-app-run.h @@ -50,6 +50,11 @@ void xdg_app_context_allow_host_fs (XdgAppContext G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppContext, xdg_app_context_free) +gboolean xdg_app_run_add_extension_args (GPtrArray *argv_array, + GKeyFile *metakey, + const char *full_ref, + GCancellable *cancellable, + GError **error); void xdg_app_run_add_environment_args (GPtrArray *argv_array, GPtrArray *dbus_proxy_argv, const char *doc_mount_path, |