nixos/etc: remove leading slash from target paths in build-composefs-dump.py

This is necessary so that duplicates in the composefs dump are avoided.
This commit is contained in:
nikstur 2024-01-28 01:55:05 +01:00
parent 92b98478a8
commit a9161ceb5a

View File

@ -58,7 +58,7 @@ class ComposefsPath:
):
if path is None:
path = attrs["target"]
self.path = "/" + path
self.path = path
self.size = size
self.filetype = filetype
self.mode = mode
@ -87,6 +87,10 @@ def eprint(*args: Any, **kwargs: Any) -> None:
print(*args, **kwargs, file=sys.stderr)
def normalize_path(path: str) -> str:
return str("/" + os.path.normpath(path).lstrip("/"))
def leading_directories(path: str) -> list[str]:
"""Return the leading directories of path
@ -145,6 +149,10 @@ def main() -> None:
paths: dict[str, ComposefsPath] = {}
for attrs in config:
# Normalize the target path to work around issues in how targets are
# declared in `environment.etc`.
attrs["target"] = normalize_path(attrs["target"])
target = attrs["target"]
source = attrs["source"]
mode = attrs["mode"]