Skip to content

Commit

Permalink
app: add 'refresh-md' command
Browse files Browse the repository at this point in the history
This is essentially the `dnf/yum makecache` equivalent for rpm-ostree.
To complete the picture, this goes hand in hand with the `-C`
equivalent, which is added in the next patch.

Closes: #1035
Approved by: cgwalters
  • Loading branch information
jlebon authored and rh-atomic-bot committed Oct 6, 2017
1 parent 7930c06 commit d0b69b4
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile-rpm-ostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -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-refresh-md.c \
src/app/rpmostree-pkg-builtins.c \
src/app/rpmostree-builtin-status.c \
src/app/rpmostree-builtin-ex.c \
Expand Down
11 changes: 11 additions & 0 deletions man/rpm-ostree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ Boston, MA 02111-1307, USA.
</listitem>
</varlistentry>

<varlistentry>
<term><command>refresh-md</command></term>

<listitem>
<para>
Download the latest rpm repo metadata if necessary and generate the
cache.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><command>cleanup</command></term>

Expand Down
5 changes: 5 additions & 0 deletions src/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ static RpmOstreeCommand commands[] = {
{ "uninstall", 0,
"Remove one or more overlay packages",
rpmostree_builtin_uninstall },
{ "refresh-md", 0,
"Generate rpm repo metadata",
rpmostree_builtin_refresh_md },
/* Legacy aliases */
{ "pkg-add", RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
NULL, rpmostree_builtin_install },
Expand All @@ -82,6 +85,8 @@ static RpmOstreeCommand commands[] = {
{ "rpm", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD |
RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
NULL, rpmostree_builtin_db },
{ "makecache", RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
NULL, rpmostree_builtin_refresh_md },
/* Hidden */
{ "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD |
RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
Expand Down
97 changes: 97 additions & 0 deletions src/app/rpmostree-builtin-refresh-md.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* Copyright (C) 2017 Jonathan Lebon <[email protected]>
*
* 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 <string.h>
#include <glib-unix.h>

#include "rpmostree-builtins.h"
#include "rpmostree-util.h"
#include "rpmostree-libbuiltin.h"
#include "rpmostree-dbus-helpers.h"

#include <libglnx.h>

static char *opt_osname;
static char *opt_force;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "force", 'f', 0, G_OPTION_ARG_NONE, &opt_force, "Expire current cache", NULL },
{ NULL }
};

static GVariant *
get_args_variant (void)
{
GVariantDict dict;
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "force", "b", opt_force);
return g_variant_dict_end (&dict);
}

int
rpmostree_builtin_refresh_md (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_refresh_md_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;
}
1 change: 1 addition & 0 deletions src/app/rpmostree-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ BUILTINPROTO(cleanup);
BUILTINPROTO(rollback);
BUILTINPROTO(initramfs);
BUILTINPROTO(status);
BUILTINPROTO(refresh_md);
BUILTINPROTO(db);
BUILTINPROTO(internals);
BUILTINPROTO(container);
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@
<arg type="s" name="transaction_address" direction="out"/>
</method>

<method name="RefreshMd">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="s" name="transaction_address" direction="out"/>
</method>

<!-- Available modifiers:
"set-refspec" (type 's')
"set-revision" (type 's')
Expand Down
61 changes: 60 additions & 1 deletion src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ os_authorize_method (GDBusInterfaceSkeleton *interface,
g_strcmp0 (method_name, "GetCachedUpdateRpmDiff") == 0 ||
g_strcmp0 (method_name, "DownloadUpdateRpmDiff") == 0 ||
g_strcmp0 (method_name, "GetCachedRebaseRpmDiff") == 0 ||
g_strcmp0 (method_name, "DownloadRebaseRpmDiff") == 0)
g_strcmp0 (method_name, "DownloadRebaseRpmDiff") == 0 ||
g_strcmp0 (method_name, "RefreshMd") == 0)

{
g_ptr_array_add (actions, "org.projectatomic.rpmostree1.repo-refresh");
}
Expand Down Expand Up @@ -958,6 +960,62 @@ os_handle_rollback (RPMOSTreeOS *interface,
return TRUE;
}

static gboolean
os_handle_refresh_md (RPMOSTreeOS *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_options)
{
RpmostreedOS *self = RPMOSTREED_OS (interface);
glnx_unref_object RpmostreedTransaction *transaction = NULL;
glnx_unref_object OstreeSysroot *ot_sysroot = NULL;
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
const char *osname;
GError *local_error = NULL;
RpmOstreeTransactionRefreshMdFlags flags = 0;
g_auto(GVariantDict) dict;

transaction = merge_compatible_txn (self, invocation);
if (transaction)
goto out;

if (!rpmostreed_sysroot_load_state (rpmostreed_sysroot_get (),
cancellable,
&ot_sysroot,
NULL,
&local_error))
goto out;

osname = rpmostree_os_get_name (interface);

g_variant_dict_init (&dict, arg_options);
if (vardict_lookup_bool (&dict, "force", FALSE))
flags |= RPMOSTREE_TRANSACTION_REFRESH_MD_FLAG_FORCE;

transaction = rpmostreed_transaction_new_refresh_md (invocation,
ot_sysroot,
flags,
osname,
cancellable,
&local_error);
if (transaction == NULL)
goto out;

rpmostreed_transaction_monitor_add (self->transaction_monitor, transaction);

out:
if (local_error != NULL)
{
g_dbus_method_invocation_take_error (invocation, local_error);
}
else
{
const char *client_address = rpmostreed_transaction_get_client_address (transaction);
rpmostree_os_complete_refresh_md (interface, invocation, client_address);
}

return TRUE;
}

/* This is an older variant of Cleanup, kept for backcompat */
static gboolean
os_handle_clear_rollback_target (RPMOSTreeOS *interface,
Expand Down Expand Up @@ -1527,6 +1585,7 @@ rpmostreed_os_iface_init (RPMOSTreeOSIface *iface)
iface->handle_rollback = os_handle_rollback;
iface->handle_clear_rollback_target = os_handle_clear_rollback_target;
iface->handle_rebase = os_handle_rebase;
iface->handle_refresh_md = os_handle_refresh_md;
iface->handle_pkg_change = os_handle_pkg_change;
iface->handle_set_initramfs_state = os_handle_set_initramfs_state;
iface->handle_cleanup = os_handle_cleanup;
Expand Down
115 changes: 115 additions & 0 deletions src/daemon/rpmostreed-transaction-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,3 +1272,118 @@ rpmostreed_transaction_new_cleanup (GDBusMethodInvocation *invocation,
return (RpmostreedTransaction *) self;

}

/* ================================ RefreshMd ================================ */

typedef struct {
RpmostreedTransaction parent;
char *osname;
RpmOstreeTransactionRefreshMdFlags flags;
} RefreshMdTransaction;

typedef RpmostreedTransactionClass RefreshMdTransactionClass;

GType refresh_md_transaction_get_type (void);

G_DEFINE_TYPE (RefreshMdTransaction,
refresh_md_transaction,
RPMOSTREED_TYPE_TRANSACTION)

static void
refresh_md_transaction_finalize (GObject *object)
{
RefreshMdTransaction *self;

self = (RefreshMdTransaction *) object;
g_free (self->osname);

G_OBJECT_CLASS (refresh_md_transaction_parent_class)->finalize (object);
}

static gboolean
refresh_md_transaction_execute (RpmostreedTransaction *transaction,
GCancellable *cancellable,
GError **error)
{
RefreshMdTransaction *self = (RefreshMdTransaction *) transaction;
OstreeSysroot *sysroot = rpmostreed_transaction_get_sysroot (transaction);

g_autoptr(OstreeDeployment) cfg_merge_deployment =
ostree_sysroot_get_merge_deployment (sysroot, self->osname);
g_autoptr(OstreeDeployment) origin_merge_deployment =
rpmostree_syscore_get_origin_merge_deployment (sysroot, self->osname);

/* but set the source root to be the origin merge deployment's so we pick up releasever */
const char *sysroot_path = gs_file_get_path_cached (ostree_sysroot_get_path (sysroot));
g_autofree char *origin_deployment_dirpath =
ostree_sysroot_get_deployment_dirpath (sysroot, origin_merge_deployment);
g_autofree char *origin_deployment_root =
g_build_filename (sysroot_path, origin_deployment_dirpath, NULL);

g_autoptr(RpmOstreeContext) ctx = rpmostree_context_new_system (cancellable, error);

/* We could bypass rpmostree_context_setup() here and call dnf_context_setup() ourselves
* since we're not actually going to perform any installation. Though it does provide us
* with the right semantics for install/source_root. So let's just play the game and
* provide a dummy treespec. */
if (!rpmostree_context_setup (ctx, NULL, origin_deployment_root, NULL, cancellable, error))
return FALSE;

if (self->flags & RPMOSTREE_TRANSACTION_REFRESH_MD_FLAG_FORCE)
{
DnfContext *hifctx = rpmostree_context_get_hif (ctx);
dnf_context_set_cache_age (hifctx, 0);
}

/* point libdnf to our repos dir */
rpmostree_context_configure_from_deployment (ctx, sysroot, cfg_merge_deployment);

if (!rpmostree_context_download_metadata (ctx, cancellable, error))
return FALSE;

return TRUE;
}

static void
refresh_md_transaction_class_init (CleanupTransactionClass *class)
{
GObjectClass *object_class;

object_class = G_OBJECT_CLASS (class);
object_class->finalize = refresh_md_transaction_finalize;

class->execute = refresh_md_transaction_execute;
}

static void
refresh_md_transaction_init (RefreshMdTransaction *self)
{
}

RpmostreedTransaction *
rpmostreed_transaction_new_refresh_md (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot,
RpmOstreeTransactionRefreshMdFlags flags,
const char *osname,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), NULL);
g_return_val_if_fail (OSTREE_IS_SYSROOT (sysroot), NULL);

RefreshMdTransaction *self =
g_initable_new (refresh_md_transaction_get_type (),
cancellable, error,
"invocation", invocation,
"sysroot-path", gs_file_get_path_cached (ostree_sysroot_get_path (sysroot)),
NULL);

if (self != NULL)
{
self->osname = g_strdup (osname);
self->flags = flags;
}

return (RpmostreedTransaction *) self;

}
12 changes: 12 additions & 0 deletions src/daemon/rpmostreed-transaction-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ rpmostreed_transaction_new_livefs (GDBusMethodInvocation *invocation,
RpmOstreeTransactionLiveFsFlags flags,
GCancellable *cancellable,
GError **error);

typedef enum {
RPMOSTREE_TRANSACTION_REFRESH_MD_FLAG_FORCE = (1 << 0),
} RpmOstreeTransactionRefreshMdFlags;

RpmostreedTransaction *
rpmostreed_transaction_new_refresh_md (GDBusMethodInvocation *invocation,
OstreeSysroot *sysroot,
RpmOstreeTransactionRefreshMdFlags flags,
const char *osname,
GCancellable *cancellable,
GError **error);

0 comments on commit d0b69b4

Please sign in to comment.