From cfd3f303b18b009a6eed5bb1d3eaf8980cdf7b64 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 19 Apr 2016 13:48:49 +0200 Subject: [PATCH] Add build-import-bundle command --- app/Makefile.am.inc | 1 + app/xdg-app-builtins-build-import-bundle.c | 94 +++++++++++++++++++++ app/xdg-app-builtins.h | 1 + app/xdg-app-main.c | 1 + doc/Makefile.am | 1 + doc/xdg-app-build-bundle.xml | 1 + doc/xdg-app-build-import-bundle.xml | 98 ++++++++++++++++++++++ doc/xdg-app.xml | 7 ++ 8 files changed, 204 insertions(+) create mode 100644 app/xdg-app-builtins-build-import-bundle.c create mode 100644 doc/xdg-app-build-import-bundle.xml diff --git a/app/Makefile.am.inc b/app/Makefile.am.inc index 146ef18e..853a8da3 100644 --- a/app/Makefile.am.inc +++ b/app/Makefile.am.inc @@ -23,6 +23,7 @@ xdg_app_SOURCES = \ app/xdg-app-builtins-build-finish.c \ app/xdg-app-builtins-build-export.c \ app/xdg-app-builtins-build-bundle.c \ + app/xdg-app-builtins-build-import-bundle.c \ app/xdg-app-builtins-build-sign.c \ app/xdg-app-builtins-repo-update.c \ app/xdg-app-builtins-document.c \ diff --git a/app/xdg-app-builtins-build-import-bundle.c b/app/xdg-app-builtins-build-import-bundle.c new file mode 100644 index 00000000..d6d80a3a --- /dev/null +++ b/app/xdg-app-builtins-build-import-bundle.c @@ -0,0 +1,94 @@ +/* + * Copyright © 2015 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: + * Alexander Larsson + */ + +#include "config.h" + +#include +#include +#include +#include + +#include "libgsystem.h" +#include "libglnx/libglnx.h" + +#include "xdg-app-builtins.h" +#include "xdg-app-utils.h" + +static GOptionEntry options[] = { + { NULL } +}; + +gboolean +xdg_app_builtin_build_import (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; + g_autoptr(GVariant) metadata = NULL; + g_autofree char *ref = NULL; + g_autofree char *to_checksum = NULL; + + context = g_option_context_new ("LOCATION FILENAME - Import a file bundle into 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 < 3) + return usage_error (context, "LOCATION and FILENAME must be specified", error); + + location = argv[1]; + filename = argv[2]; + + 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 (!ostree_repo_open (repo, cancellable, error)) + return FALSE; + + metadata = xdg_app_bundle_load (file, &to_checksum, + &ref, + NULL, + NULL, + NULL, + error); + if (metadata == NULL) + return FALSE; + + g_print ("Importing %s (%s)\n", ref, to_checksum); + if (!xdg_app_pull_from_bundle (repo, file, + NULL, ref, FALSE, + cancellable, + error)) + return FALSE; + + return TRUE; +} diff --git a/app/xdg-app-builtins.h b/app/xdg-app-builtins.h index c71253ee..f0dbde9a 100644 --- a/app/xdg-app-builtins.h +++ b/app/xdg-app-builtins.h @@ -68,6 +68,7 @@ BUILTINPROTO(build_finish); BUILTINPROTO(build_sign); BUILTINPROTO(build_export); BUILTINPROTO(build_bundle); +BUILTINPROTO(build_import); BUILTINPROTO(build_update_repo); BUILTINPROTO(export_file); BUILTINPROTO(override); diff --git a/app/xdg-app-main.c b/app/xdg-app-main.c index 87edbfb8..504a7fbc 100644 --- a/app/xdg-app-main.c +++ b/app/xdg-app-main.c @@ -70,6 +70,7 @@ static XdgAppCommand commands[] = { { "build-finish", xdg_app_builtin_build_finish, "Finish a build dir for export" }, { "build-export", xdg_app_builtin_build_export, "Export a build dir to a repository" }, { "build-bundle", xdg_app_builtin_build_bundle, "Create a bundle file from a build directory" }, + { "build-import-bundle", xdg_app_builtin_build_import, "Import a bundle file" }, { "build-sign", xdg_app_builtin_build_sign, "Sign an application or runtime" }, { "build-update-repo", xdg_app_builtin_build_update_repo, "Update the summary file in a repository" }, diff --git a/doc/Makefile.am b/doc/Makefile.am index fa641ea9..6d70e236 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -34,6 +34,7 @@ man_MANS = \ xdg-app-build-init.1 \ xdg-app-build.1 \ xdg-app-build-bundle.1 \ + xdg-app-build-import-bundle.1 \ xdg-app-build-finish.1 \ xdg-app-build-export.1 \ xdg-app-build-update-repo.1 \ diff --git a/doc/xdg-app-build-bundle.xml b/doc/xdg-app-build-bundle.xml index 435d2935..bac719f8 100644 --- a/doc/xdg-app-build-bundle.xml +++ b/doc/xdg-app-build-bundle.xml @@ -142,6 +142,7 @@ xdg-app-build-init1, xdg-app-build1, xdg-app-build-finish1, + xdg-app-build-import-bundle1, xdg-app-repo-update1 diff --git a/doc/xdg-app-build-import-bundle.xml b/doc/xdg-app-build-import-bundle.xml new file mode 100644 index 00000000..ebc9dd9f --- /dev/null +++ b/doc/xdg-app-build-import-bundle.xml @@ -0,0 +1,98 @@ + + + + + + + xdg-app build-import-bundle + xdg-app + + + + Developer + Alexander + Larsson + alexl@redhat.com + + + + + + xdg-app build-import-bundle + 1 + + + + xdg-app-build-import-bundle + Import a file bundle into a local repository + + + + + xdg-app build-import-bundle + OPTION + LOCATION + FILENAME + + + + + Description + + + Imports a bundle from a file named FILENAME + into the repository at LOCATION. + + + The format of the bundle file is that generated by build-bundle. + + + + + Options + + The following options are understood: + + + + + + + + Show help options and exit. + + + + + + + + + Print debug information during command processing. + + + + + + + + Print version information and exit. + + + + + + + See also + + + ostree1, + xdg-app1, + xdg-app-build-bundle1, + xdg-app-repo-update1 + + + + + diff --git a/doc/xdg-app.xml b/doc/xdg-app.xml index 033b8b91..f5a1d0c6 100644 --- a/doc/xdg-app.xml +++ b/doc/xdg-app.xml @@ -255,6 +255,13 @@ Create a bundle file from a build directory. + + xdg-app-build-import-bundle1 + + + Import a file bundle into a local repository. + + xdg-app-build-update-repo1