Skip to content

Commit

Permalink
nixos/etc: remove leading slash from target paths in build-composefs-…
Browse files Browse the repository at this point in the history
…dump.py

This is necessary so that duplicates in the composefs dump are avoided.
  • Loading branch information
nikstur committed Jan 28, 2024
1 parent 92b9847 commit a9161ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nixos/modules/system/etc/build-composefs-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
):
if path is None:
path = attrs["target"]
self.path = "/" + path
self.path = path
self.size = size
self.filetype = filetype
self.mode = mode
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit a9161ce

Please sign in to comment.