diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-02-13 22:46:11 +0100 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-02-26 20:21:50 +0100 |
commit | e3a6e380337820d17c154c54eaf50ab95bba5c0d (patch) | |
tree | a7e1cdc262c9927dc025e856f670c052eb472c98 /lib/fileset/internal.nix | |
parent | c5b544922979418b8ed0d25f66fe344c9ef96fa7 (diff) |
lib.fileset.toList: init
Diffstat (limited to 'lib/fileset/internal.nix')
-rw-r--r-- | lib/fileset/internal.nix | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index f4fcc83e10124..0d97ef1745683 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -18,6 +18,7 @@ let attrNames attrValues mapAttrs + mapAttrsToList optionalAttrs zipAttrsWith ; @@ -29,6 +30,7 @@ let inherit (lib.lists) all commonPrefix + concatLists elemAt filter findFirst @@ -539,6 +541,27 @@ rec { ${baseNameOf root} = rootPathType; }; + # Turns a file set into the list of file paths it includes. + # Type: fileset -> [ Path ] + _toList = fileset: + let + recurse = path: tree: + if isAttrs tree then + concatLists (mapAttrsToList (name: value: + recurse (path + "/${name}") value + ) tree) + else if tree == "directory" then + recurse path (readDir path) + else if tree == null then + [ ] + else + [ path ]; + in + if fileset._internalIsEmptyWithoutBase then + [ ] + else + recurse fileset._internalBase fileset._internalTree; + # Transforms the filesetTree of a file set to a shorter base path, e.g. # _shortenTreeBase [ "foo" ] (_create /foo/bar null) # => { bar = null; } |