summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-19 13:48:49 +0200
committerAlexander Larsson <alexl@redhat.com>2016-04-19 13:53:26 +0200
commitcfd3f303b18b009a6eed5bb1d3eaf8980cdf7b64 (patch)
tree00ebf4da91fa6b2fd0db8681ae60e0c80635d7ac /app
parent1c1bc4acca467bdb15e8c75f3ef3f802d9cafea0 (diff)
downloadxdg-app-cfd3f303b18b009a6eed5bb1d3eaf8980cdf7b64.tar.gz
Add build-import-bundle command
Diffstat (limited to 'app')
-rw-r--r--app/Makefile.am.inc1
-rw-r--r--app/xdg-app-builtins-build-import-bundle.c94
-rw-r--r--app/xdg-app-builtins.h1
-rw-r--r--app/xdg-app-main.c1
4 files changed, 97 insertions, 0 deletions
diff --git a/app/Makefile.am.inc b/app/Makefile.am.inc
index 146ef18..853a8da 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 0000000..d6d80a3
--- /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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Alexander Larsson <alexl@redhat.com>
+ */
+
+#include "config.h"
+
+#include <locale.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#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 c71253e..f0dbde9 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 87edbfb..504a7fb 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" },