diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index becd13f4c5..cf432e2177 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1217,16 +1217,19 @@ static int dissect_image( } if (m->partitions[type.designator].found) { + int c; + /* For most partition types the first one we see wins. Except for the * rootfs and /usr, where we do a version compare of the label, and * let the newest version win. This permits a simple A/B versioning * scheme in OS images. */ - if (compare_arch(type.arch, m->partitions[type.designator].architecture) <= 0) + c = compare_arch(type.arch, m->partitions[type.designator].architecture); + if (c < 0) /* the arch we already found is better than the one we found now */ continue; - - if (!partition_designator_is_versioned(type.designator) || - strverscmp_improved(m->partitions[type.designator].label, label) >= 0) + if (c == 0 && /* same arch? then go by version in label */ + (!partition_designator_is_versioned(type.designator) || + strverscmp_improved(label, m->partitions[type.designator].label) <= 0)) continue; dissected_partition_done(m->partitions + type.designator);