lib.fileset: start by recursing into the initial element

This is guaranteed to be safe. The tree can be a simple string if the
fileset is the same as the root, but the `or` takes care of that. In the
`or` case, the tree is guaranteed to fail the isAttrs check, and so even
though the index is invalid, it won't matter.
This commit is contained in:
Eman Resu
2026-08-12 14:51:50 -04:00
parent 3b58c2719e
commit ef34f35e45

View File

@@ -563,7 +563,12 @@ rec {
# or a string ("directory" or "regular", etc.) in which case it's included
localTree != null;
in
recurse 0 tree;
# Start by recursing into the first element. This is guaranteed to be
# safe. components will never be empty (builtins.split can't make an
# empty list). Tree can be something other than an attrset, but if so,
# the isAttrs check will fail when being passed `or tree`, and the index
# being ahead doesn't matter.
recurse 2 (tree.${head components} or tree);
# Filter suited when there's no files
empty = _: _: false;