From b1d4ec3de0fb9bdf1b243112de7606ac7eea70ad Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 4 Oct 2017 15:20:16 +0000 Subject: [PATCH] app: add 'makecache' command This is essentially the `dnf`/`yum` equivalent for rpm-ostree. To complete the picture, we're missing the `-C` equivalent as well for all the commands that make use of this metadata. Though `makecache` on its own should be particularly helpful in test environment provisioning where one may have cached metadata available to inject and just wants rpm-ostree to sanity check it. --- Makefile-rpm-ostree.am | 1 + man/rpm-ostree.xml | 11 ++ src/app/main.c | 3 + src/app/rpmostree-builtin-makecache.c | 94 ++++++++++++++++ src/app/rpmostree-builtins.h | 1 + .../org.projectatomic.rpmostree1.policy | 11 ++ src/daemon/org.projectatomic.rpmostree1.xml | 5 + src/daemon/rpmostree-sysroot-upgrader.c | 24 +--- src/daemon/rpmostreed-daemon.c | 2 +- src/daemon/rpmostreed-os.c | 54 +++++++++ src/daemon/rpmostreed-transaction-types.c | 106 ++++++++++++++++++ src/daemon/rpmostreed-transaction-types.h | 7 ++ src/libpriv/rpmostree-core.c | 31 +++-- src/libpriv/rpmostree-core.h | 7 +- 14 files changed, 325 insertions(+), 32 deletions(-) create mode 100644 src/app/rpmostree-builtin-makecache.c diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index f283d6fccf..2e14e5d951 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -32,6 +32,7 @@ rpm_ostree_SOURCES = src/app/main.c \ src/app/rpmostree-builtin-initramfs.c \ src/app/rpmostree-builtin-livefs.c \ src/app/rpmostree-builtin-override.c \ + src/app/rpmostree-builtin-makecache.c \ src/app/rpmostree-pkg-builtins.c \ src/app/rpmostree-builtin-status.c \ src/app/rpmostree-builtin-ex.c \ diff --git a/man/rpm-ostree.xml b/man/rpm-ostree.xml index afa68d6244..3b6ec600cd 100644 --- a/man/rpm-ostree.xml +++ b/man/rpm-ostree.xml @@ -353,6 +353,17 @@ Boston, MA 02111-1307, USA. + + makecache + + + + Download the latest rpm repo metadata if necessary and generate the + cache. + + + + cleanup diff --git a/src/app/main.c b/src/app/main.c index df5f7bc9d8..71e14f9544 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -74,6 +74,9 @@ static RpmOstreeCommand commands[] = { { "uninstall", 0, "Remove one or more overlay packages", rpmostree_builtin_uninstall }, + { "makecache", 0, + "Generate rpm repo metadata", + rpmostree_builtin_makecache }, /* Legacy aliases */ { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_HIDDEN, NULL, rpmostree_builtin_install }, diff --git a/src/app/rpmostree-builtin-makecache.c b/src/app/rpmostree-builtin-makecache.c new file mode 100644 index 0000000000..ed16bbf986 --- /dev/null +++ b/src/app/rpmostree-builtin-makecache.c @@ -0,0 +1,94 @@ +/* Copyright (C) 2017 Jonathan Lebon + * + * 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 licence 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, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include +#include + +#include "rpmostree-builtins.h" +#include "rpmostree-util.h" +#include "rpmostree-libbuiltin.h" +#include "rpmostree-dbus-helpers.h" + +#include + +static char *opt_osname; + +static GOptionEntry option_entries[] = { + { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" }, + { NULL } +}; + +static GVariant * +get_args_variant (void) +{ + GVariantDict dict; + g_variant_dict_init (&dict, NULL); + return g_variant_dict_end (&dict); +} + +int +rpmostree_builtin_makecache (int argc, + char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GOptionContext) context = g_option_context_new (""); + glnx_unref_object RPMOSTreeOS *os_proxy = NULL; + glnx_unref_object RPMOSTreeSysroot *sysroot_proxy = NULL; + g_autofree char *transaction_address = NULL; + _cleanup_peer_ GPid peer_pid = 0; + + if (!rpmostree_option_context_parse (context, + option_entries, + &argc, &argv, + invocation, + cancellable, + NULL, NULL, + &sysroot_proxy, + &peer_pid, + error)) + return EXIT_FAILURE; + + if (argc < 1 || argc > 2) + { + rpmostree_usage_error (context, "Too few or too many arguments", error); + return EXIT_FAILURE; + } + + if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, + cancellable, &os_proxy, error)) + return EXIT_FAILURE; + + if (!rpmostree_os_call_make_cache_sync (os_proxy, + get_args_variant (), + &transaction_address, + cancellable, + error)) + return EXIT_FAILURE; + + if (!rpmostree_transaction_get_response_sync (sysroot_proxy, + transaction_address, + cancellable, + error)) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 2ddab3038a..e619d953b6 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -68,6 +68,7 @@ BUILTINPROTO(cleanup); BUILTINPROTO(rollback); BUILTINPROTO(initramfs); BUILTINPROTO(status); +BUILTINPROTO(makecache); BUILTINPROTO(db); BUILTINPROTO(internals); BUILTINPROTO(container); diff --git a/src/daemon/org.projectatomic.rpmostree1.policy b/src/daemon/org.projectatomic.rpmostree1.policy index 304e89db75..1c6b5f7e7d 100644 --- a/src/daemon/org.projectatomic.rpmostree1.policy +++ b/src/daemon/org.projectatomic.rpmostree1.policy @@ -30,6 +30,17 @@ + + Generate rpm repo metadata cache + Authentication is required to generate cache + package-x-generic + + auth_admin + auth_admin + auth_admin_keep + + + Override packages Authentication is required to override base OS software diff --git a/src/daemon/org.projectatomic.rpmostree1.xml b/src/daemon/org.projectatomic.rpmostree1.xml index bd88941317..df8c20cc59 100644 --- a/src/daemon/org.projectatomic.rpmostree1.xml +++ b/src/daemon/org.projectatomic.rpmostree1.xml @@ -225,6 +225,11 @@ + + + + +