Blame SOURCES/0201-blscfg-sort-BLS-entries-by-version-field.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Will Thompson <wjt@endlessm.com>
d9d99f
Date: Wed, 11 Jul 2018 15:41:09 +0100
d9d99f
Subject: [PATCH] blscfg: sort BLS entries by 'version' field
d9d99f
MIME-Version: 1.0
d9d99f
Content-Type: text/plain; charset=UTF-8
d9d99f
Content-Transfer-Encoding: 8bit
d9d99f
d9d99f
This partially reverts ‘Use BLS fragment filename as menu entry id and
d9d99f
for criteria to sort’. Sorting by filename only gives the correct order
d9d99f
if the BLS entries are generated by a version of ostree after this patch
d9d99f
https://github.com/ostreedev/ostree/commit/9f48e212a3bf9ed418fb3216e4f834d581bc520e
d9d99f
to use the version (higher is newer) in the filename. Older ostrees,
d9d99f
including all releases at the time of writing, use the index (lower is
d9d99f
newer) in the filename, so sorting by filename produces the reverse
d9d99f
order.
d9d99f
d9d99f
Sorting by 'version' field matches libostree's own
d9d99f
compare_boot_loader_configs(), so I think it's more correct than relying
d9d99f
on the filename, particularly since we've already gone to the trouble of
d9d99f
parsing all the fields in the file.
d9d99f
d9d99f
Signed-off-by: Will Thompson <wjt@endlessm.com>
d9d99f
---
d9d99f
 grub-core/commands/blscfg.c | 16 ++++++++++++++++
d9d99f
 1 file changed, 16 insertions(+)
d9d99f
d9d99f
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
b71686
index b61dddb7f..9c928dda4 100644
d9d99f
--- a/grub-core/commands/blscfg.c
d9d99f
+++ b/grub-core/commands/blscfg.c
d9d99f
@@ -327,10 +327,26 @@ finish:
d9d99f
     return ret;
d9d99f
 }
d9d99f
 
d9d99f
+/* return 1: p0 is newer than p1 */
d9d99f
+/*        0: p0 and p1 are the same version */
d9d99f
+/*       -1: p1 is newer than p0 */
d9d99f
 static int bls_cmp(const void *p0, const void *p1, void *state UNUSED)
d9d99f
 {
d9d99f
   struct bls_entry * e0 = *(struct bls_entry **)p0;
d9d99f
   struct bls_entry * e1 = *(struct bls_entry **)p1;
d9d99f
+  const char *v0, *v1;
d9d99f
+  int r;
d9d99f
+
d9d99f
+  v0 = bls_get_val(e0, "version", NULL);
d9d99f
+  v1 = bls_get_val(e1, "version", NULL);
d9d99f
+
d9d99f
+  if (v0 && !v1)
d9d99f
+    return -1;
d9d99f
+  if (!v0 && v1)
d9d99f
+    return 1;
d9d99f
+
d9d99f
+  if ((r = vercmp(v0, v1)) != 0)
d9d99f
+    return r;
d9d99f
 
d9d99f
   return vercmp(e0->filename, e1->filename);
d9d99f
 }