libpriv: Add a helper function to print pkg diff

I want to use this in livefs, where I'll end up doing some diff
computations on the server and am currently rendering text there.

It might also be a step towards using this in `db diff`.

Closes: #709
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-04-21 16:23:33 -04:00 committed by Atomic Bot
parent 999e0034ef
commit 7d98e3efc8
5 changed files with 99 additions and 74 deletions

View File

@ -53,6 +53,7 @@ librpmostreepriv_la_SOURCES = \
librpmostreepriv_la_CFLAGS = \
$(AM_CFLAGS) \
-I$(srcdir)/src/lib \
-I$(srcdir)/src/libpriv \
-I$(libglnx_srcpath) \
-DPKGLIBDIR=\"$(pkglibdir)\" \

View File

@ -65,17 +65,20 @@ CLEANFILES += \
tests/common/compose/test-repo-local.repo \
$(NULL)
tests_check_jsonutil_CPPFLAGS = $(AM_CPPFLAGS) -I $(srcdir)/src/libpriv -I $(srcdir)/libglnx
tests_check_jsonutil_CFLAGS = $(AM_CFLAGS) $(PKGDEP_RPMOSTREE_CFLAGS)
tests_check_jsonutil_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
testbin_cppflags = $(AM_CPPFLAGS) -I $(srcdir)/src/libpriv -I $(srcdir)/libglnx
testbin_cflags = $(AM_CFLAGS) $(PKGDEP_RPMOSTREE_CFLAGS)
testbin_ldadd = $(PKGDEP_RPMOSTREE_LIBS) librpmostree-1.la librpmostreepriv.la
tests_check_jsonutil_CPPFLAGS = $(testbin_cppflags)
tests_check_jsonutil_CFLAGS = $(testbin_cflags)
tests_check_jsonutil_LDADD = $(testbin_ldadd)
tests_check_cache_branch_to_nevra_CPPFLAGS = $(AM_CPPFLAGS) -I $(srcdir)/src/libpriv -I $(srcdir)/libglnx
tests_check_cache_branch_to_nevra_CFLAGS = $(AM_CFLAGS) $(PKGDEP_RPMOSTREE_CFLAGS)
tests_check_cache_branch_to_nevra_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
tests_check_cache_branch_to_nevra_CPPFLAGS = $(testbin_cppflags)
tests_check_cache_branch_to_nevra_CFLAGS = $(testbin_cflags)
tests_check_cache_branch_to_nevra_LDADD = $(testbin_ldadd)
tests_check_postprocess_CPPFLAGS = $(AM_CPPFLAGS) -I $(srcdir)/src/libpriv -I $(srcdir)/libglnx
tests_check_postprocess_CFLAGS = $(AM_CFLAGS) $(PKGDEP_RPMOSTREE_CFLAGS)
tests_check_postprocess_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la
tests_check_postprocess_CPPFLAGS = $(testbin_cppflags)
tests_check_postprocess_CFLAGS = $(testbin_cflags)
tests_check_postprocess_LDADD = $(testbin_ldadd)
tests/check/test-compose.sh: tests/common/compose/test-repo.repo

View File

@ -24,6 +24,7 @@
#include "rpmostree-libbuiltin.h"
#include "rpmostree.h"
#include "rpmostree-util.h"
#include "libglnx.h"
@ -43,6 +44,7 @@ rpmostree_usage_error (GOptionContext *context,
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
}
/* Print the diff between the booted and pending deployments */
gboolean
rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
GCancellable *cancellable,
@ -64,6 +66,7 @@ out:
return ret;
}
/* Print the diff between the booted and pending deployments */
gboolean
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
GCancellable *cancellable,
@ -89,8 +92,6 @@ rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
g_autoptr(GPtrArray) added = NULL;
g_autoptr(GPtrArray) modified_old = NULL;
g_autoptr(GPtrArray) modified_new = NULL;
gboolean first;
guint i;
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
goto out;
@ -100,69 +101,7 @@ rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
cancellable, error))
goto out;
g_assert (modified_old->len == modified_new->len);
first = TRUE;
for (i = 0; i < modified_old->len; i++)
{
RpmOstreePackage *oldpkg = modified_old->pdata[i];
RpmOstreePackage *newpkg = modified_new->pdata[i];
const char *name = rpm_ostree_package_get_name (oldpkg);
if (rpm_ostree_package_cmp (oldpkg, newpkg) > 0)
continue;
if (first)
{
g_print ("Upgraded:\n");
first = FALSE;
}
g_print (" %s %s -> %s\n", name,
rpm_ostree_package_get_evr (oldpkg),
rpm_ostree_package_get_evr (newpkg));
}
first = TRUE;
for (i = 0; i < modified_old->len; i++)
{
RpmOstreePackage *oldpkg = modified_old->pdata[i];
RpmOstreePackage *newpkg = modified_new->pdata[i];
const char *name = rpm_ostree_package_get_name (oldpkg);
if (rpm_ostree_package_cmp (oldpkg, newpkg) < 0)
continue;
if (first)
{
g_print ("Downgraded:\n");
first = FALSE;
}
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);
}
rpmostree_diff_print (repo, removed, added, modified_old, modified_new);
}
ret = TRUE;

View File

@ -28,6 +28,7 @@
#include "rpmostree-util.h"
#include "rpmostree-origin.h"
#include "rpmostree.h"
#include "libglnx.h"
int
@ -613,3 +614,78 @@ rpmostree_cache_branch_to_nevra (const char *cachebranch)
return g_string_free (r, FALSE);
}
/* Given the result of rpm_ostree_db_diff(), print it. */
void
rpmostree_diff_print (OstreeRepo *repo,
GPtrArray *removed,
GPtrArray *added,
GPtrArray *modified_old,
GPtrArray *modified_new)
{
gboolean first;
g_assert (modified_old->len == modified_new->len);
first = TRUE;
for (guint i = 0; i < modified_old->len; i++)
{
RpmOstreePackage *oldpkg = modified_old->pdata[i];
RpmOstreePackage *newpkg = modified_new->pdata[i];
const char *name = rpm_ostree_package_get_name (oldpkg);
if (rpm_ostree_package_cmp (oldpkg, newpkg) > 0)
continue;
if (first)
{
g_print ("Upgraded:\n");
first = FALSE;
}
g_print (" %s %s -> %s\n", name,
rpm_ostree_package_get_evr (oldpkg),
rpm_ostree_package_get_evr (newpkg));
}
first = TRUE;
for (guint i = 0; i < modified_old->len; i++)
{
RpmOstreePackage *oldpkg = modified_old->pdata[i];
RpmOstreePackage *newpkg = modified_new->pdata[i];
const char *name = rpm_ostree_package_get_name (oldpkg);
if (rpm_ostree_package_cmp (oldpkg, newpkg) < 0)
continue;
if (first)
{
g_print ("Downgraded:\n");
first = FALSE;
}
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 (guint 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 (guint 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);
}
}

View File

@ -85,6 +85,12 @@ gs_file_get_path_cached (GFile *file)
return rpmostree_file_get_path_cached (file);
}
void rpmostree_diff_print (OstreeRepo *repo,
GPtrArray *removed,
GPtrArray *added,
GPtrArray *modified_old,
GPtrArray *modified_new);
gboolean
rpmostree_deployment_get_layered_info (OstreeRepo *repo,
OstreeDeployment *deployment,