nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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