From: Zbigniew Jędrzejewski-Szmek Date: Fri, 20 Oct 2017 15:51:54 +0000 (+0200) Subject: sd-boot: simplify the implementation of entry uniquification X-Git-Tag: v236~174^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2fa605a653faff46a39f069e28441e89b3db6dd;p=thirdparty%2Fsystemd.git sd-boot: simplify the implementation of entry uniquification There's a slight change in implementation: we first try to append the version, then look for any non-unique pairs again. Before, we would only mark as possibly unique those entries we changed. But if there are two entries that e.g. have the same title and version, but only one has the machine-id specified, we would treat one of them as still non-unique after appending the machine-id to the other one. So the new algorithm is simpler but more robust (not that it matters). --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 12176f1fe0c..8e4c9d0395b 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -1305,10 +1305,29 @@ static VOID config_default_entry_select(Config *config) { config->idx_default = -1; } +static BOOLEAN find_nonunique(ConfigEntry **entries, UINTN entry_count) { + BOOLEAN non_unique = FALSE; + UINTN i, k; + + for (i = 0; i < entry_count; i++) + entries[i]->non_unique = FALSE; + + for (i = 0; i < entry_count; i++) + for (k = 0; k < entry_count; k++) { + if (i == k) + continue; + if (StrCmp(entries[i]->title_show, entries[k]->title_show) != 0) + continue; + + non_unique = entries[i]->non_unique = entries[k]->non_unique = TRUE; + } + + return non_unique; +} + /* generate a unique title, avoiding non-distinguishable menu entries */ static VOID config_title_generate(Config *config) { - UINTN i, k; - BOOLEAN unique; + UINTN i; /* set title */ for (i = 0; i < config->entry_count; i++) { @@ -1321,20 +1340,7 @@ static VOID config_title_generate(Config *config) { config->entries[i]->title_show = StrDuplicate(title); } - unique = TRUE; - for (i = 0; i < config->entry_count; i++) { - for (k = 0; k < config->entry_count; k++) { - if (i == k) - continue; - if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0) - continue; - - unique = FALSE; - config->entries[i]->non_unique = TRUE; - config->entries[k]->non_unique = TRUE; - } - } - if (unique) + if (!find_nonunique(config->entries, config->entry_count)) return; /* add version to non-unique titles */ @@ -1349,23 +1355,9 @@ static VOID config_title_generate(Config *config) { s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, config->entries[i]->version); FreePool(config->entries[i]->title_show); config->entries[i]->title_show = s; - config->entries[i]->non_unique = FALSE; } - unique = TRUE; - for (i = 0; i < config->entry_count; i++) { - for (k = 0; k < config->entry_count; k++) { - if (i == k) - continue; - if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0) - continue; - - unique = FALSE; - config->entries[i]->non_unique = TRUE; - config->entries[k]->non_unique = TRUE; - } - } - if (unique) + if (!find_nonunique(config->entries, config->entry_count)) return; /* add machine-id to non-unique titles */ @@ -1383,24 +1375,10 @@ static VOID config_title_generate(Config *config) { s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, m); FreePool(config->entries[i]->title_show); config->entries[i]->title_show = s; - config->entries[i]->non_unique = FALSE; FreePool(m); } - unique = TRUE; - for (i = 0; i < config->entry_count; i++) { - for (k = 0; k < config->entry_count; k++) { - if (i == k) - continue; - if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0) - continue; - - unique = FALSE; - config->entries[i]->non_unique = TRUE; - config->entries[k]->non_unique = TRUE; - } - } - if (unique) + if (!find_nonunique(config->entries, config->entry_count)) return; /* add file name to non-unique titles */