]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot+bootctl: invert order of entries w/o sort-key 22791/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Mar 2022 18:05:03 +0000 (19:05 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 18 Mar 2022 18:11:59 +0000 (19:11 +0100)
With the changes in 20ec8f534f90c94669ac8f9a50869f22f94fd4c8, we would sort
entries with sort-key as expected (higher versions earlier, i.e. at the top of
the menu), but entries without the sort-key as before, with higher versions
later.

When we have a bunch of boot entries grouped by machine-id (or even in the
typical case of all boot entries having the same machine id), sorting by id
should generally give good results. Entries will be grouped by installation,
and then newer entries should generally be at the top of the menu.

src/boot/efi/boot.c
src/shared/bootspec.c
src/test/test-bootspec.c

index 9ed8daed42ecdbc1d3789032c349c9364d460636..e5399f372829ae36c8be5204bedfd88c8a92d9ae 100644 (file)
@@ -1683,10 +1683,10 @@ static INTN config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) {
                         return r;
         }
 
-        /* Now order by ID (the version is likely part of the ID, thus note that this might put the oldest
-         * version last, not first, i.e. specifying a sort key explicitly is thus generally preferable, to
-         * take benefit of the explicit sorting above.) */
-        r = strverscmp_improved(a->id, b->id);
+        /* Now order by ID. The version is likely part of the ID, thus note that this will generatelly put
+         * the newer versions earlier. Specifying a sort key explicitly is preferable, because it gives an
+         * explicit sort order. */
+        r = -strverscmp_improved(a->id, b->id);
         if (r != 0)
                 return r;
 
index 96ec6ecb9ebbbe07a8302cd663e3aaf744cc5306..a87cce4ea57e0e38e13036d6ba02f3965607bf62 100644 (file)
@@ -272,6 +272,7 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
         r = CMP(!a->sort_key, !b->sort_key);
         if (r != 0)
                 return r;
+
         if (a->sort_key && b->sort_key) {
                 r = strcmp(a->sort_key, b->sort_key);
                 if (r != 0)
@@ -286,7 +287,7 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
                         return r;
         }
 
-        return strverscmp_improved(a->id, b->id);
+        return -strverscmp_improved(a->id, b->id);
 }
 
 static int boot_entries_find(
index 47d0f58c965437c464d438e9ec15f64fcbdba2df..7ba44744ba67d46c3a6419b7b4dd0bce4fe88f36 100644 (file)
@@ -86,9 +86,9 @@ TEST_RET(bootspec_sort) {
         assert_se(streq(config.entries[2].id, "c.conf"));
 
         /* The following ones have no sort key, hence order by version compared ids, lowest first */
-        assert_se(streq(config.entries[3].id, "a-5.conf"));
+        assert_se(streq(config.entries[3].id, "b.conf"));
         assert_se(streq(config.entries[4].id, "a-10.conf"));
-        assert_se(streq(config.entries[5].id, "b.conf"));
+        assert_se(streq(config.entries[5].id, "a-5.conf"));
 
         return 0;
 }