Move diff printing code into client
This is a step forward to deduplicating; the client tooling now calls into the public API for diffs, rather than using the older internal function. Note: this patch also links the client against the public library.
This commit is contained in:
parent
3326e13481
commit
e414be8ae2
@ -29,6 +29,8 @@ rpm_ostree_SOURCES = src/app/main.c \
|
||||
src/app/rpmostree-db-builtin-diff.c \
|
||||
src/app/rpmostree-db-builtin-list.c \
|
||||
src/app/rpmostree-db-builtin-version.c \
|
||||
src/app/rpmostree-libbuiltin.c \
|
||||
src/app/rpmostree-libbuiltin.h \
|
||||
$(NULL)
|
||||
|
||||
if BUILDOPT_COMPOSE_TOOLING
|
||||
@ -39,8 +41,8 @@ rpm_ostree_SOURCES += \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
|
||||
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
|
||||
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/app -I$(srcdir)/src/lib -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
|
||||
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la librpmostree-1.la
|
||||
|
||||
privdatadir=$(pkglibdir)
|
||||
privdata_DATA = src/app/tmpfiles-ostree-integration.conf
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include "rpmostree-builtins.h"
|
||||
#include "rpmostree-util.h"
|
||||
#include "rpmostree-treepkgdiff.h"
|
||||
#include "rpmostree-libbuiltin.h"
|
||||
|
||||
#include "libgsystem.h"
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <glib-unix.h>
|
||||
|
||||
#include "rpmostree-builtins.h"
|
||||
#include "rpmostree-treepkgdiff.h"
|
||||
#include "rpmostree-libbuiltin.h"
|
||||
|
||||
#include "libgsystem.h"
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "rpmostree-builtins.h"
|
||||
#include "rpmostree-treepkgdiff.h"
|
||||
#include "rpmostree-libbuiltin.h"
|
||||
#include "rpmostree-rpm-util.h"
|
||||
|
||||
#include "libgsystem.h"
|
||||
|
106
src/app/rpmostree-libbuiltin.c
Normal file
106
src/app/rpmostree-libbuiltin.c
Normal file
@ -0,0 +1,106 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2014 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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 "rpmostree-libbuiltin.h"
|
||||
#include "rpmostree.h"
|
||||
#include "rpmostree-cleanup.h"
|
||||
|
||||
gboolean
|
||||
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeDeployment *booted_deployment;
|
||||
OstreeDeployment *new_deployment;
|
||||
gs_unref_ptrarray GPtrArray *deployments =
|
||||
ostree_sysroot_get_deployments (sysroot);
|
||||
|
||||
booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
|
||||
|
||||
g_assert (deployments->len > 1);
|
||||
new_deployment = deployments->pdata[0];
|
||||
|
||||
if (booted_deployment && new_deployment != booted_deployment)
|
||||
{
|
||||
gs_unref_object OstreeRepo *repo = NULL;
|
||||
const char *from_rev = ostree_deployment_get_csum (booted_deployment);
|
||||
const char *to_rev = ostree_deployment_get_csum (new_deployment);
|
||||
g_autoptr(GPtrArray) removed = NULL;
|
||||
g_autoptr(GPtrArray) added = NULL;
|
||||
g_autoptr(GPtrArray) modified_old = NULL;
|
||||
g_autoptr(GPtrArray) modified_new = NULL;
|
||||
guint i;
|
||||
|
||||
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!rpm_ostree_db_diff (repo, from_rev, to_rev, NULL,
|
||||
&removed, &added, &modified_old, &modified_new,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (modified_old->len > 0)
|
||||
g_print ("Changed:\n");
|
||||
|
||||
for (i = 0; i < modified_old->len; i++)
|
||||
{
|
||||
RpmOstreePackage *oldpkg = modified_old->pdata[i];
|
||||
RpmOstreePackage *newpkg;
|
||||
const char *name = rpm_ostree_package_get_name (oldpkg);
|
||||
|
||||
g_assert_cmpuint (i, <, modified_new->len);
|
||||
|
||||
newpkg = modified_old->pdata[i];
|
||||
|
||||
g_print (" %s %s -> %s\n", name,
|
||||
rpm_ostree_package_get_evr (oldpkg),
|
||||
rpm_ostree_package_get_evr (newpkg));
|
||||
}
|
||||
|
||||
if (removed->len > 0)
|
||||
g_print ("Removed:\n");
|
||||
for (i = 0; i < removed->len; i++)
|
||||
{
|
||||
RpmOstreePackage *pkg = removed->pdata[i];
|
||||
const char *nevra = rpm_ostree_package_get_nevra (pkg);
|
||||
|
||||
g_print (" %s\n", nevra);
|
||||
}
|
||||
|
||||
if (added->len > 0)
|
||||
g_print ("Added:\n");
|
||||
for (i = 0; i < added->len; i++)
|
||||
{
|
||||
RpmOstreePackage *pkg = added->pdata[i];
|
||||
const char *nevra = rpm_ostree_package_get_nevra (pkg);
|
||||
|
||||
g_print (" %s\n", nevra);
|
||||
}
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
31
src/app/rpmostree-libbuiltin.h
Normal file
31
src/app/rpmostree-libbuiltin.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostree.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean
|
||||
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
G_END_DECLS
|
@ -97,137 +97,6 @@ rpmostree_get_pkglist_for_root (int dfd,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
print_rpmdb_diff (int dfd,
|
||||
const char *oldroot,
|
||||
const char *newroot,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
_cleanup_hysack_ HySack old_sack = NULL;
|
||||
_cleanup_hypackagelist_ HyPackageList old_pkglist = NULL;
|
||||
_cleanup_hysack_ HySack new_sack = NULL;
|
||||
_cleanup_hypackagelist_ HyPackageList new_pkglist = NULL;
|
||||
guint i;
|
||||
HyPackage pkg;
|
||||
gboolean printed_header = FALSE;
|
||||
|
||||
if (!rpmostree_get_pkglist_for_root (dfd, oldroot, &old_sack, &old_pkglist,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!rpmostree_get_pkglist_for_root (dfd, newroot, &new_sack, &new_pkglist,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
printed_header = FALSE;
|
||||
FOR_PACKAGELIST(pkg, new_pkglist, i)
|
||||
{
|
||||
_cleanup_hyquery_ HyQuery query = NULL;
|
||||
_cleanup_hypackagelist_ HyPackageList pkglist = NULL;
|
||||
|
||||
query = hy_query_create (old_sack);
|
||||
hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
|
||||
hy_query_filter (query, HY_PKG_EVR, HY_NEQ, hy_package_get_evr (pkg));
|
||||
hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
|
||||
pkglist = hy_query_run (query);
|
||||
if (hy_packagelist_count (pkglist) > 0)
|
||||
{
|
||||
gs_free char *nevra = hy_package_get_nevra (pkg);
|
||||
if (!printed_header)
|
||||
{
|
||||
g_print ("Changed:\n");
|
||||
printed_header = TRUE;
|
||||
}
|
||||
g_print (" %s\n", nevra);
|
||||
}
|
||||
}
|
||||
|
||||
printed_header = FALSE;
|
||||
FOR_PACKAGELIST(pkg, old_pkglist, i)
|
||||
{
|
||||
_cleanup_hyquery_ HyQuery query = NULL;
|
||||
_cleanup_hypackagelist_ HyPackageList pkglist = NULL;
|
||||
|
||||
query = hy_query_create (new_sack);
|
||||
hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
|
||||
hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
|
||||
pkglist = hy_query_run (query);
|
||||
if (hy_packagelist_count (pkglist) == 0)
|
||||
{
|
||||
gs_free char *nevra = hy_package_get_nevra (pkg);
|
||||
if (!printed_header)
|
||||
{
|
||||
g_print ("Removed:\n");
|
||||
printed_header = TRUE;
|
||||
}
|
||||
g_print (" %s\n", nevra);
|
||||
}
|
||||
}
|
||||
|
||||
printed_header = FALSE;
|
||||
FOR_PACKAGELIST(pkg, new_pkglist, i)
|
||||
{
|
||||
_cleanup_hyquery_ HyQuery query = NULL;
|
||||
_cleanup_hypackagelist_ HyPackageList pkglist = NULL;
|
||||
|
||||
query = hy_query_create (old_sack);
|
||||
hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
|
||||
hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
|
||||
pkglist = hy_query_run (query);
|
||||
if (hy_packagelist_count (pkglist) == 0)
|
||||
{
|
||||
gs_free char *nevra = hy_package_get_nevra (pkg);
|
||||
if (!printed_header)
|
||||
{
|
||||
g_print ("Added:\n");
|
||||
printed_header = TRUE;
|
||||
}
|
||||
g_print (" %s\n", nevra);
|
||||
}
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeDeployment *booted_deployment;
|
||||
OstreeDeployment *new_deployment;
|
||||
gs_unref_ptrarray GPtrArray *deployments =
|
||||
ostree_sysroot_get_deployments (sysroot);
|
||||
int sysroot_dfd;
|
||||
|
||||
booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
|
||||
|
||||
g_assert (deployments->len > 1);
|
||||
new_deployment = deployments->pdata[0];
|
||||
|
||||
sysroot_dfd = ostree_sysroot_get_fd (sysroot);
|
||||
|
||||
if (booted_deployment && new_deployment != booted_deployment)
|
||||
{
|
||||
g_autofree char *booted_root =
|
||||
ostree_sysroot_get_deployment_dirpath (sysroot, booted_deployment);
|
||||
g_autofree char *new_root =
|
||||
ostree_sysroot_get_deployment_dirpath (sysroot, new_deployment);
|
||||
|
||||
if (!print_rpmdb_diff (sysroot_dfd, booted_root, new_root, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
pkg_array_compare (HyPackage *p_pkg1,
|
||||
HyPackage *p_pkg2)
|
||||
|
@ -38,10 +38,6 @@ rpmostree_get_pkglist_for_root (int dfd,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
rpmostree_print_transaction (HifContext *context);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user