Skip to content

Commit

Permalink
libpriv: Add a helper function to print pkg diff
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
cgwalters committed Apr 25, 2017
1 parent aabdb6d commit 21c8954
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 65 deletions.
1 change: 1 addition & 0 deletions Makefile-libpriv.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)\" \
Expand Down
69 changes: 4 additions & 65 deletions src/app/rpmostree-libbuiltin.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "rpmostree-libbuiltin.h"
#include "rpmostree.h"
#include "rpmostree-util.h"

#include "libglnx.h"

Expand All @@ -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,
Expand All @@ -64,6 +66,7 @@ rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
return ret;
}

/* Print the diff between the booted and pending deployments */
gboolean
rpmostree_print_treepkg_diff (OstreeSysroot *sysroot,
GCancellable *cancellable,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
76 changes: 76 additions & 0 deletions src/libpriv/rpmostree-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "rpmostree-util.h"
#include "rpmostree-origin.h"
#include "rpmostree.h"
#include "libglnx.h"

int
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/libpriv/rpmostree-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 21c8954

Please sign in to comment.