lib/package: Handle arch pkg transitions

Let's try to match expectations a bit from the dnf/yum world and
describe e.g. a `noarch` package become archful as an upgrade rather
than a removal and an addition. This was originally implicitly supported
(before PR #1230) by the fact that we didn't compare arches at all (and
in fact, arches don't even show up in a `db diff` output for modified
packages).

We bring this back here, but only in the simple case that it's a single
package. We still don't try to do any fancy handling for packages of the
same name.

Closes: #1272

Closes: #1274
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-02-26 22:06:26 +00:00 committed by Atomic Bot
parent 64968436e6
commit 829a746821
2 changed files with 39 additions and 8 deletions

View File

@ -297,6 +297,15 @@ _rpm_ostree_package_list_for_commit (OstreeRepo *repo,
return TRUE;
}
static inline gboolean
next_pkg_has_different_name (const char *name, GPtrArray *pkgs, guint cur_i)
{
if (cur_i + 1 >= pkgs->len)
return TRUE;
RpmOstreePackage *pkg = g_ptr_array_index (pkgs, cur_i + 1);
return !g_str_equal (name, pkg->name);
}
/* Kinda like `comm(1)`, but for RpmOstreePackage lists. Assuming the pkglists are sorted,
* this is more efficient than launching hundreds of queries and works with both dnf-based
* and rpmdb.pkglist-based RpmOstreePackage arrays. Packages with different arches (e.g.
@ -366,7 +375,18 @@ _rpm_ostree_diff_package_lists (GPtrArray *a,
}
else
{
if (cmp < 0)
/* if it's just a *single* package of that name that changed arch, let's catch
* it to match yum/dnf. otherwise (multilib), just report them separately. */
const gboolean single_a = next_pkg_has_different_name (pkg_a->name, a, cur_a);
const gboolean single_b = next_pkg_has_different_name (pkg_b->name, b, cur_b);
if (single_a && single_b)
{
g_ptr_array_add (modified_a, g_object_ref (pkg_a));
g_ptr_array_add (modified_b, g_object_ref (pkg_b));
cur_a++;
cur_b++;
}
else if (cmp < 0)
{
g_ptr_array_add (unique_a, g_object_ref (pkg_a));
cur_a++;

View File

@ -45,13 +45,15 @@ check_not_diff() {
vm_build_rpm pkg-to-remove
vm_build_rpm pkg-to-replace
vm_rpmostree install pkg-to-remove pkg-to-replace
vm_build_rpm pkg-to-replace-archtrans arch noarch
vm_rpmostree install pkg-to-remove pkg-to-replace pkg-to-replace-archtrans
booted_csum=$(vm_get_booted_csum)
pending_csum=$(vm_get_pending_csum)
check_diff $booted_csum $pending_csum \
+pkg-to-remove \
+pkg-to-replace
+pkg-to-replace \
+pkg-to-replace-archtrans
# now let's make the pending csum become an update
vm_cmd ostree commit -b vmcheck --tree=ref=$pending_csum
@ -60,12 +62,16 @@ vm_rpmostree upgrade
pending_csum=$(vm_get_pending_csum)
check_diff $booted_csum $pending_csum \
+pkg-to-remove \
+pkg-to-replace
+pkg-to-replace \
+pkg-to-replace-archtrans
echo "ok setup"
vm_rpmostree override remove pkg-to-remove
vm_build_rpm pkg-to-replace version 2.0
vm_rpmostree override replace $YUMREPO/pkg-to-replace-2.0-1.x86_64.rpm
vm_build_rpm pkg-to-replace-archtrans version 2.0
vm_rpmostree override replace \
$YUMREPO/pkg-to-replace-2.0-1.x86_64.rpm \
$YUMREPO/pkg-to-replace-archtrans-2.0-1.x86_64.rpm
vm_build_rpm pkg-to-overlay build 'echo same > pkg-to-overlay'
# some multilib handling tests (override default /bin script to skip conflicts)
vm_build_rpm pkg-to-overlay build 'echo same > pkg-to-overlay' arch i686
@ -76,7 +82,8 @@ check_diff $booted_csum $pending_layered_csum \
+pkg-to-overlay-1.0-1.x86_64 \
+pkg-to-overlay-1.0-1.i686 \
+glibc-1.0-1.i686 \
+pkg-to-replace-2.0
+pkg-to-replace-2.0 \
+pkg-to-replace-archtrans-2.0
# check that regular glibc is *not* in the list of modified/dropped packages
check_not_diff $booted_csum $pending_layered_csum \
=glibc \
@ -91,7 +98,9 @@ check_diff $pending_csum $pending_layered_csum \
+glibc-1.0-1.i686 \
-pkg-to-remove \
!pkg-to-replace-1.0 \
=pkg-to-replace-2.0
=pkg-to-replace-2.0 \
!pkg-to-replace-archtrans-1.0 \
=pkg-to-replace-archtrans-2.0
echo "ok db diff"
# this is a bit convoluted; basically, we prune the commit and only keep its
@ -111,5 +120,7 @@ check_diff $pending_csum $pending_layered_csum \
+glibc-1.0-1.i686 \
-pkg-to-remove \
!pkg-to-replace-1.0 \
=pkg-to-replace-2.0
=pkg-to-replace-2.0 \
!pkg-to-replace-archtrans-1.0 \
=pkg-to-replace-archtrans-2.0
echo "ok db from pkglist.metadata"