From e414be8ae2bce8ba3c1ca0bedd01097771b82df3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 19 Apr 2015 09:36:53 -0400 Subject: [PATCH] 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. --- Makefile-rpm-ostree.am | 6 +- src/app/rpmostree-builtin-rebase.c | 2 +- src/app/rpmostree-builtin-rollback.c | 2 +- src/app/rpmostree-builtin-upgrade.c | 2 +- src/app/rpmostree-libbuiltin.c | 106 ++++++++++++++++++++++ src/app/rpmostree-libbuiltin.h | 31 +++++++ src/libpriv/rpmostree-treepkgdiff.c | 131 --------------------------- src/libpriv/rpmostree-treepkgdiff.h | 6 +- 8 files changed, 145 insertions(+), 141 deletions(-) create mode 100644 src/app/rpmostree-libbuiltin.c create mode 100644 src/app/rpmostree-libbuiltin.h diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index fbe76865..ceb97ead 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -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 diff --git a/src/app/rpmostree-builtin-rebase.c b/src/app/rpmostree-builtin-rebase.c index 5bbb7d92..ab46cc02 100644 --- a/src/app/rpmostree-builtin-rebase.c +++ b/src/app/rpmostree-builtin-rebase.c @@ -25,7 +25,7 @@ #include "rpmostree-builtins.h" #include "rpmostree-util.h" -#include "rpmostree-treepkgdiff.h" +#include "rpmostree-libbuiltin.h" #include "libgsystem.h" diff --git a/src/app/rpmostree-builtin-rollback.c b/src/app/rpmostree-builtin-rollback.c index 03192bc2..f729382e 100644 --- a/src/app/rpmostree-builtin-rollback.c +++ b/src/app/rpmostree-builtin-rollback.c @@ -24,7 +24,7 @@ #include #include "rpmostree-builtins.h" -#include "rpmostree-treepkgdiff.h" +#include "rpmostree-libbuiltin.h" #include "libgsystem.h" diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 432eac8a..acc2e3d4 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -25,7 +25,7 @@ #include #include "rpmostree-builtins.h" -#include "rpmostree-treepkgdiff.h" +#include "rpmostree-libbuiltin.h" #include "rpmostree-rpm-util.h" #include "libgsystem.h" diff --git a/src/app/rpmostree-libbuiltin.c b/src/app/rpmostree-libbuiltin.c new file mode 100644 index 00000000..2fa573f3 --- /dev/null +++ b/src/app/rpmostree-libbuiltin.c @@ -0,0 +1,106 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2014 Colin Walters + * + * 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; +} diff --git a/src/app/rpmostree-libbuiltin.h b/src/app/rpmostree-libbuiltin.h new file mode 100644 index 00000000..d63e7b12 --- /dev/null +++ b/src/app/rpmostree-libbuiltin.h @@ -0,0 +1,31 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2014 Anne LoVerso + * + * 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 + +G_BEGIN_DECLS + +gboolean +rpmostree_print_treepkg_diff (OstreeSysroot *sysroot, + GCancellable *cancellable, + GError **error); +G_END_DECLS diff --git a/src/libpriv/rpmostree-treepkgdiff.c b/src/libpriv/rpmostree-treepkgdiff.c index 00639d5d..49a4f1de 100644 --- a/src/libpriv/rpmostree-treepkgdiff.c +++ b/src/libpriv/rpmostree-treepkgdiff.c @@ -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) diff --git a/src/libpriv/rpmostree-treepkgdiff.h b/src/libpriv/rpmostree-treepkgdiff.h index 12819e31..7d3a4214 100644 --- a/src/libpriv/rpmostree-treepkgdiff.h +++ b/src/libpriv/rpmostree-treepkgdiff.h @@ -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); +