tools/osbuild-image-info: make read_boot_entries() more robust

`read_boot_entries()` could previously fail when trying to split lines
in bootloader entries, which contained only "\n" and became empty
string after stripping whitespace characters. This is the case e.g. on
F41 images.

Moreover, bootloader entries can contain comments as lines starting with
"#", which were previously not ignored by the function and would end up
in the parsed entry and could potentially fail to be split.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-12-31 06:07:07 +01:00 committed by Tomáš Hozza
parent 2c3f528488
commit ee3f0ab59a

View file

@ -366,7 +366,14 @@ def read_boot_entries(boot_dir):
entries = []
for conf in glob.glob(f"{boot_dir}/loader/entries/*.conf"):
with open(conf) as f:
entries.append(dict(line.strip().split(" ", 1) for line in f))
entry = dict()
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
key, value = line.split(" ", 1)
entry[key] = value
entries.append(entry)
return sorted(entries, key=lambda e: e["title"])