From 18bb0868e9e9ca169e1fcdf8a2a9a3fe54dcef5b Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 19 Apr 2016 13:19:36 +0200 Subject: [PATCH] build-bundle: Split out bundle building to helper --- app/xdg-app-builtins-build-bundle.c | 135 +++++++++++++++------------- 1 file changed, 74 insertions(+), 61 deletions(-) diff --git a/app/xdg-app-builtins-build-bundle.c b/app/xdg-app-builtins-build-bundle.c index a52981b3..f20c3247 100644 --- a/app/xdg-app-builtins-build-bundle.c +++ b/app/xdg-app-builtins-build-bundle.c @@ -90,73 +90,24 @@ read_gpg_data (GCancellable *cancellable, return xdg_app_read_stream (source_stream, FALSE, error); } -gboolean -xdg_app_builtin_build_bundle (int argc, char **argv, GCancellable *cancellable, GError **error) +static gboolean +build_bundle (OstreeRepo *repo, GFile *file, + const char *name, const char *full_branch, + GBytes *gpg_data, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(GFile) file = NULL; - g_autoptr(GFile) repofile = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GBytes) gpg_data = NULL; - g_autoptr(GFile) root = NULL; - g_autoptr(GFile) metadata_file = NULL; - g_autoptr(GInputStream) in = NULL; - g_autoptr(GInputStream) xml_in = NULL; - const char *location; - const char *filename; - const char *name; - const char *branch; - g_autofree char *full_branch = NULL; - g_autofree char *commit_checksum = NULL; GVariantBuilder metadata_builder; GVariantBuilder param_builder; - g_autoptr(XdgAppXml) xml_root = NULL; - g_autoptr(GFile) appstream_file = NULL; g_autoptr(GKeyFile) keyfile = NULL; g_autoptr(GFile) xmls_dir = NULL; + g_autoptr(GFile) metadata_file = NULL; + g_autoptr(XdgAppXml) xml_root = NULL; + g_autoptr(GFile) appstream_file = NULL; g_autofree char *appstream_basename = NULL; - - context = g_option_context_new ("LOCATION FILENAME NAME [BRANCH] - Create a single file bundle from a local repository"); - - if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) - return FALSE; - - if (argc < 4) - return usage_error (context, "LOCATION, FILENAME and NAME must be specified", error); - - location = argv[1]; - filename = argv[2]; - name = argv[3]; - - if (argc >= 5) - branch = argv[4]; - else - branch = "master"; - - repofile = g_file_new_for_commandline_arg (location); - repo = ostree_repo_new (repofile); - - if (!xdg_app_supports_bundles (repo)) - return xdg_app_fail (error, "Your version of ostree is too old to support single-file bundles"); - - if (!g_file_query_exists (repofile, cancellable)) - return xdg_app_fail (error, "'%s' is not a valid repository", location); - - file = g_file_new_for_commandline_arg (filename); - - if (!xdg_app_is_valid_name (name)) - return xdg_app_fail (error, "'%s' is not a valid name", name); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - if (opt_runtime) - full_branch = xdg_app_build_runtime_ref (name, branch, opt_arch); - else - full_branch = xdg_app_build_app_ref (name, branch, opt_arch); - - if (!ostree_repo_open (repo, cancellable, error)) - return FALSE; + g_autoptr(GInputStream) in = NULL; + g_autoptr(GInputStream) xml_in = NULL; + g_autoptr(GFile) root = NULL; + g_autofree char *commit_checksum = NULL; if (!ostree_repo_resolve_rev (repo, full_branch, FALSE, &commit_checksum, error)) return FALSE; @@ -293,3 +244,65 @@ xdg_app_builtin_build_bundle (int argc, char **argv, GCancellable *cancellable, return TRUE; } + +gboolean +xdg_app_builtin_build_bundle (int argc, char **argv, GCancellable *cancellable, GError **error) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(GFile) repofile = NULL; + g_autoptr(OstreeRepo) repo = NULL; + g_autoptr(GBytes) gpg_data = NULL; + const char *location; + const char *filename; + const char *name; + const char *branch; + g_autofree char *full_branch = NULL; + + context = g_option_context_new ("LOCATION FILENAME NAME [BRANCH] - Create a single file bundle from a local repository"); + + if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) + return FALSE; + + if (argc < 4) + return usage_error (context, "LOCATION, FILENAME and NAME must be specified", error); + + location = argv[1]; + filename = argv[2]; + name = argv[3]; + + if (argc >= 5) + branch = argv[4]; + else + branch = "master"; + + repofile = g_file_new_for_commandline_arg (location); + repo = ostree_repo_new (repofile); + + if (!xdg_app_supports_bundles (repo)) + return xdg_app_fail (error, "Your version of ostree is too old to support single-file bundles"); + + if (!g_file_query_exists (repofile, cancellable)) + return xdg_app_fail (error, "'%s' is not a valid repository", location); + + file = g_file_new_for_commandline_arg (filename); + + if (!xdg_app_is_valid_name (name)) + return xdg_app_fail (error, "'%s' is not a valid name", name); + + if (!xdg_app_is_valid_branch (branch)) + return xdg_app_fail (error, "'%s' is not a valid branch name", branch); + + if (opt_runtime) + full_branch = xdg_app_build_runtime_ref (name, branch, opt_arch); + else + full_branch = xdg_app_build_app_ref (name, branch, opt_arch); + + if (!ostree_repo_open (repo, cancellable, error)) + return FALSE; + + if (!build_bundle (repo, file, name, full_branch, gpg_data, cancellable, error)) + return FALSE; + + return TRUE; +}