Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
21 changes: 5 additions & 16 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,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;
Expand All @@ -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,
Expand Down
52 changes: 52 additions & 0 deletions src/rpmostree-builtin-rpm.h
Original file line number Diff line number Diff line change
@@ -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);
90 changes: 75 additions & 15 deletions src/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@

#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"

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 +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);
Expand All @@ -78,19 +84,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 +127,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;
_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;
#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