Skip to content

Commit 17712d3

Browse files
poetteringbluca
authored andcommitted
bootspec: implement sorting by tries left/done, to match what sd-boot does
(cherry picked from commit 35451a3) (cherry picked from commit 3736e21) (cherry picked from commit 0672a43) (cherry picked from commit 43a6208) (cherry picked from commit 57077a0)
1 parent 99cb634 commit 17712d3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/shared/bootspec.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
522522
assert(a);
523523
assert(b);
524524

525+
/* This mimics a function of the same name in src/boot/efi/sd-boot.c */
526+
527+
r = CMP(a->tries_left == 0, b->tries_left == 0);
528+
if (r != 0)
529+
return r;
530+
525531
r = CMP(!a->sort_key, !b->sort_key);
526532
if (r != 0)
527533
return r;
@@ -540,7 +546,18 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
540546
return r;
541547
}
542548

543-
return -strverscmp_improved(a->id, b->id);
549+
r = -strverscmp_improved(a->id, b->id);
550+
if (r != 0)
551+
return r;
552+
553+
if (a->tries_left != UINT_MAX || b->tries_left != UINT_MAX)
554+
return 0;
555+
556+
r = -CMP(a->tries_left, b->tries_left);
557+
if (r != 0)
558+
return r;
559+
560+
return CMP(a->tries_done, b->tries_done);
544561
}
545562

546563
static void inode_hash_func(const struct stat *q, struct siphash *state) {

0 commit comments

Comments
 (0)