Skip to content

Commit

Permalink
upgrade: Download only /usr/share/rpm in check-diff
Browse files Browse the repository at this point in the history
        This improves on the check-diff option by only downloading the
        /usr/share/rpm directory to do a package diff.  This prevents downloading
        the whole deployment and the necessity to do a cleanup later.
  • Loading branch information
aloverso committed Aug 21, 2014
1 parent acfb219 commit a323574
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Makefile-rpm-ostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ librpmostree_la_SOURCES = \
src/rpmostree-util.h \
src/hif-utils.c \
src/hif-utils.h \
src/rpmostree-treepkgdiff.c \
src/rpmostree-treepkgdiff.h \
src/rpmostree-builtin-rpm.h \
$(NULL)
if BUILDOPT_PATCHED_HAWKEY_AND_LIBSOLV
librpmostree_la_SOURCES += \
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LT_INIT([disable-static])
PKG_PROG_PKG_CONFIG

PKG_CHECK_MODULES(PKGDEP_GIO_UNIX, [gio-unix-2.0])
PKG_CHECK_MODULES(PKGDEP_RPMOSTREE, [gio-unix-2.0 json-glib-1.0 ostree-1 >= 2014.4 libgsystem rpm hawkey])
PKG_CHECK_MODULES(PKGDEP_RPMOSTREE, [gio-unix-2.0 json-glib-1.0 ostree-1 >= 2014.4 libsoup-2.4 libgsystem rpm hawkey])
AC_PATH_PROG([XSLTPROC], [xsltproc])

GOBJECT_INTROSPECTION_REQUIRE([1.34.0])
Expand Down
4 changes: 2 additions & 2 deletions man/rpm-ostree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ Boston, MA 02111-1307, USA.
<command>--reboot</command> or <command>-r </command> to initiate a reboot after upgrade is prepared.
</para>

<para><command>--allow-downgrade</command> to permit deployment of chronologically older trees.
<para><command>--allow-downgrade</command> to permit deployment of chronologically older trees.</para>

</para>
<para><option>--check-diff</option> to download only /usr/share/rpm in order to do a package-level diff between the two versions.</para>
</listitem>
</varlistentry>

Expand Down
15 changes: 4 additions & 11 deletions src/rpmostree-builtin-rpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "rpmostree-builtins.h"
#include "rpmostree-treepkgdiff.h"
#include "rpmostree-util.h"
#include "rpmostree-builtin-rpm.h"

/* FIXME: */
#define OSTREE_GIO_FAST_QUERYINFO ("standard::name,standard::type,standard::size,standard::is-symlink,standard::symlink-target," \
Expand Down Expand Up @@ -517,7 +518,7 @@ _RPMOSTREE_DEFINE_TRIVIAL_CLEANUP_FUNC(struct RpmHeadersDiff *,

#define _cleanup_rpmhdrs_diff_ __attribute__((cleanup(rpmhdrs_diff_freep)))

static struct RpmHeadersDiff *
struct RpmHeadersDiff *
rpmhdrs_diff (struct RpmHeaders *l1,
struct RpmHeaders *l2)
{
Expand Down Expand Up @@ -592,7 +593,7 @@ _rpmhdrs_diff_cmp_end (const GPtrArray *hs1, const GPtrArray *hs2)
static void
_gptr_array_reverse (GPtrArray *data);

static void
void
rpmhdrs_diff_prnt_diff (GFile *root1, GFile *root2, struct RpmHeadersDiff *diff,
GCancellable *cancellable,
GError **error)
Expand Down Expand Up @@ -820,14 +821,6 @@ rpmhdrs_diff_prnt_block (GFile *root1, GFile *root2,
rpmhdrs_diff_free (diff);
}

/* data needed to extract rpm/yum data from a commit revision */
struct RpmRevisionData
{
struct RpmHeaders *rpmdb;
GFile *root;
char *commit;
};

static void
rpmrev_free (struct RpmRevisionData *ptr)
{
Expand All @@ -853,7 +846,7 @@ _RPMOSTREE_DEFINE_TRIVIAL_CLEANUP_FUNC(struct RpmRevisionData *, rpmrev_free);

#define _cleanup_rpmrev_ __attribute__((cleanup(rpmrev_freep)))

static struct RpmRevisionData *
struct RpmRevisionData *
rpmrev_new (OstreeRepo *repo, GFile *rpmdbdir, const char *rev,
const GPtrArray *patterns,
GCancellable *cancellable,
Expand Down
44 changes: 44 additions & 0 deletions src/rpmostree-builtin-rpm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2014 Anne LoVerso <anne.loverso@students.olin.edu>
*
* 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 <rpm/rpmlib.h>
#include <rpm/rpmlog.h>

struct RpmRevisionData
{
struct RpmHeaders *rpmdb;
GFile *root;
char *commit;
};

struct RpmHeadersDiff *
rpmhdrs_diff (struct RpmHeaders *l1,
struct RpmHeaders *l2);

void
rpmhdrs_diff_prnt_diff (GFile *root1, GFile *root2, struct RpmHeadersDiff *diff,
GCancellable *cancellable,
GError **error);

struct RpmRevisionData *
rpmrev_new (OstreeRepo *repo, GFile *rpmdbdir, const char *rev,
const GPtrArray *patterns,
GCancellable *cancellable,
GError **error);
92 changes: 77 additions & 15 deletions src/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,29 @@

#include <string.h>
#include <glib-unix.h>
#include <gio/gio.h>

#include <libsoup/soup.h>

#include "rpmostree-builtins.h"
#include "rpmostree-treepkgdiff.h"
#include "rpmostree-pull-progress.h"
#include "rpmostree-builtin-rpm.h"

#include "libgsystem.h"

static char *opt_sysroot = "/";
static char *opt_osname;
static gboolean opt_reboot;
static gboolean opt_allow_downgrade;
static gboolean opt_check_diff;

static GOptionEntry option_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after an upgrade is prepared", NULL },
{ "allow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_allow_downgrade, "Permit deployment of chronologically older trees", NULL },
{ "check-diff", 0, 0, G_OPTION_ARG_NONE, &opt_check_diff, "Check for upgrades and print package diff only", NULL },
{ NULL }
};

Expand All @@ -57,11 +63,13 @@ rpmostree_builtin_upgrade (int argc,
GSConsole *console = NULL;
gboolean changed;
OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;

gs_free char *origin_description = NULL;

gs_unref_object OstreeRepo *repo = NULL;

g_option_context_add_main_entries (context, option_entries, NULL);

if (!g_option_context_parse (context, &argc, &argv, error))
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;

sysroot_path = g_file_new_for_path (opt_sysroot);
Expand All @@ -78,19 +86,32 @@ rpmostree_builtin_upgrade (int argc,
if (origin_description)
g_print ("Updating from: %s\n", origin_description);

if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
goto out;

console = gs_console_get ();
if (console)
{
gs_console_begin_status_line (console, "", NULL, NULL);
progress = ostree_async_progress_new_and_connect (_rpmostree_pull_progress, console);
}

if (opt_allow_downgrade)
if (opt_allow_downgrade)
upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER;

if (!ostree_sysroot_upgrader_pull (upgrader, 0, 0, progress, &changed,
if (opt_check_diff)
{
if (!ostree_sysroot_upgrader_pull_one_dir (upgrader, "/usr/share/rpm", 0, 0, progress, &changed,
cancellable, error))
goto out;
goto out;
}

else
{
if (!ostree_sysroot_upgrader_pull (upgrader, 0, 0, progress, &changed,
cancellable, error))
goto out;
}

if (console)
{
Expand All @@ -108,21 +129,62 @@ rpmostree_builtin_upgrade (int argc,
}
else
{
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
goto out;
if (!opt_check_diff)
{
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
goto out;

if (opt_reboot)
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
"systemctl", "reboot", NULL);
else
{
#ifdef HAVE_PATCHED_HAWKEY_AND_LIBSOLV
if (!rpmostree_print_treepkg_diff (sysroot, cancellable, error))
goto out;
#endif

g_print ("Updates prepared for next boot; run \"systemctl reboot\" to start a reboot\n");
}
}


if (opt_reboot)
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
"systemctl", "reboot", NULL);
else
{
#ifdef HAVE_PATCHED_HAWKEY_AND_LIBSOLV
if (!rpmostree_print_treepkg_diff (sysroot, cancellable, error))
gs_unref_object GFile *rpmdbdir = NULL;
struct RpmRevisionData *rpmrev1 = NULL;
struct RpmRevisionData *rpmrev2 = NULL;

gs_free char *tmpd = g_mkdtemp (g_strdup ("/tmp/rpm-ostree.XXXXXX"));

gs_free char *ref = NULL; // location of this rev
gs_free char *remote = NULL;

if (!ostree_parse_refspec (origin_description, &remote, &ref, error))
goto out;

if (rpmReadConfigFiles (NULL, NULL))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"rpm failed to init: %s", rpmlogMessage());
goto out;
}

rpmdbdir = g_file_new_for_path (tmpd);

if (!(rpmrev1 = rpmrev_new (repo, rpmdbdir,
ostree_deployment_get_csum (ostree_sysroot_get_booted_deployment (sysroot)),
NULL, cancellable, error)))
goto out;

if (!(rpmrev2 = rpmrev_new (repo, rpmdbdir, ref,
NULL, cancellable, error)))
goto out;
#endif

g_print ("Updates prepared for next boot; run \"systemctl reboot\" to start a reboot\n");
rpmhdrs_diff_prnt_diff (rpmrev1->root, rpmrev2->root,
rpmhdrs_diff (rpmrev1->rpmdb, rpmrev2->rpmdb),
cancellable, error);
}
}

Expand Down

0 comments on commit a323574

Please sign in to comment.