Skip to content

Commit 43a6208

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)
1 parent 71da938 commit 43a6208

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
@@ -530,6 +530,12 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
530530
assert(a);
531531
assert(b);
532532

533+
/* This mimics a function of the same name in src/boot/efi/sd-boot.c */
534+
535+
r = CMP(a->tries_left == 0, b->tries_left == 0);
536+
if (r != 0)
537+
return r;
538+
533539
r = CMP(!a->sort_key, !b->sort_key);
534540
if (r != 0)
535541
return r;
@@ -548,7 +554,18 @@ static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
548554
return r;
549555
}
550556

551-
return -strverscmp_improved(a->id, b->id);
557+
r = -strverscmp_improved(a->id, b->id);
558+
if (r != 0)
559+
return r;
560+
561+
if (a->tries_left != UINT_MAX || b->tries_left != UINT_MAX)
562+
return 0;
563+
564+
r = -CMP(a->tries_left, b->tries_left);
565+
if (r != 0)
566+
return r;
567+
568+
return CMP(a->tries_done, b->tries_done);
552569
}
553570

554571
static int config_check_inode_relevant_and_unseen(BootConfig *config, int fd, const char *fname) {

0 commit comments

Comments
 (0)