mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
nixos/systemd-boot-builder: verify content of existing entry files
A file named nixos-<hash>.conf whose content no longer hashes to <hash> is corrupt. Skip it so GC removes it and a fresh entry is written.
This commit is contained in:
@@ -194,14 +194,17 @@ class BootFile:
|
||||
) -> tuple["BootFile", str]:
|
||||
contents_hash = hashlib.sha256(contents).hexdigest()
|
||||
path_prefix = f"nixos-{contents_hash}"
|
||||
pat = re.compile(rf"{re.escape(path_prefix)}(\+[0-9]+(-[0-9]+)?)?\.conf")
|
||||
path = None
|
||||
for e in os.scandir(path=BOOT_MOUNT_POINT / "loader" / "entries"):
|
||||
mat = re.fullmatch(
|
||||
rf"{re.escape(path_prefix)}(\+[0-9]+(-[0-9]+)?)?\.conf", e.name
|
||||
)
|
||||
if mat is not None:
|
||||
path = Path("loader/entries") / e.name
|
||||
break
|
||||
if pat.fullmatch(e.name) is None:
|
||||
continue
|
||||
# Ignore files whose content does not match the hash in their
|
||||
# name so GC removes them and a fresh entry is written.
|
||||
if hashlib.sha256(Path(e.path).read_bytes()).hexdigest() != contents_hash:
|
||||
continue
|
||||
path = Path("loader/entries") / e.name
|
||||
break
|
||||
if path is None:
|
||||
counters = f"+{BOOT_COUNTING_TRIES}" if BOOT_COUNTING else ""
|
||||
path = Path(f"loader/entries/{path_prefix}{counters}.conf")
|
||||
|
||||
Reference in New Issue
Block a user