upgrade: Download only /usr/share/rpm in check-diff

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.
This commit is contained in:
Anne LoVerso 2014-08-05 08:21:54 -04:00 committed by Colin Walters
parent acfb219c36
commit 00162a2eea
5 changed files with 138 additions and 34 deletions

View File

@ -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 += \

View File

@ -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>

View File

@ -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," \
@ -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)
{
@ -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)
@ -820,15 +821,7 @@ 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
void
rpmrev_free (struct RpmRevisionData *ptr)
{
gs_unref_object GFile *root = NULL;
@ -849,11 +842,7 @@ rpmrev_free (struct RpmRevisionData *ptr)
g_free (ptr);
}
_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,

View File

@ -0,0 +1,52 @@
/* -*- 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>
#include "rpmostree-util.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);
void
rpmrev_free (struct RpmRevisionData *ptr);
_RPMOSTREE_DEFINE_TRIVIAL_CLEANUP_FUNC(struct RpmRevisionData *, rpmrev_free);
#define _cleanup_rpmrev_ __attribute__((cleanup(rpmrev_freep)))
struct RpmRevisionData *
rpmrev_new (OstreeRepo *repo, GFile *rpmdbdir, const char *rev,
const GPtrArray *patterns,
GCancellable *cancellable,
GError **error);

View File

@ -22,10 +22,12 @@
#include <string.h>
#include <glib-unix.h>
#include <gio/gio.h>
#include "rpmostree-builtins.h"
#include "rpmostree-treepkgdiff.h"
#include "rpmostree-pull-progress.h"
#include "rpmostree-builtin-rpm.h"
#include "libgsystem.h"
@ -33,12 +35,14 @@ 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 }
};
@ -57,11 +61,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);
@ -78,6 +84,9 @@ 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)
{
@ -85,12 +94,22 @@ rpmostree_builtin_upgrade (int argc,
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)
{
@ -108,21 +127,62 @@ rpmostree_builtin_upgrade (int argc,
}
else
{
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
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;
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");
g_print ("Updates prepared for next boot; run \"systemctl reboot\" to start a reboot\n");
}
}
else
{
gs_unref_object GFile *rpmdbdir = NULL;
_cleanup_rpmrev_ struct RpmRevisionData *rpmrev1 = NULL;
_cleanup_rpmrev_ 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;
rpmhdrs_diff_prnt_diff (rpmrev1->root, rpmrev2->root,
rpmhdrs_diff (rpmrev1->rpmdb, rpmrev2->rpmdb),
cancellable, error);
}
}