summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2023-11-14 06:50:54 +0100
committerSilvan Mosberger <contact@infinisil.com>2023-11-14 07:29:57 +0100
commite1d833173839985fdb5dfa3dc3d93bf7db374737 (patch)
tree9bc94c19bc37f6be38fd0c44ff37742748b2032b /lib
parentf3565a2c088883636f198550eac349ed82c6a2b3 (diff)
downloadnixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar.gz
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar.bz2
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar.lz
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar.xz
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.tar.zst
nixpkgs-e1d833173839985fdb5dfa3dc3d93bf7db374737.zip
lib.fileset.fileFilter: Minor cleanups and more tests
Diffstat (limited to 'lib')
-rw-r--r--lib/fileset/default.nix4
-rw-r--r--lib/fileset/internal.nix4
-rwxr-xr-xlib/fileset/tests.sh7
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/fileset/default.nix b/lib/fileset/default.nix
index fe7b304ba69..54aace0ea14 100644
--- a/lib/fileset/default.nix
+++ b/lib/fileset/default.nix
@@ -304,7 +304,7 @@ in {
       fileFilter (file: hasPrefix "." file.name) ./.
 
       # Include all regular files (not symlinks or others) in the current directory
-      fileFilter (file: file.type == "regular")
+      fileFilter (file: file.type == "regular") ./.
   */
   fileFilter =
     /*
@@ -325,7 +325,7 @@ in {
     fileset:
     if ! isFunction predicate then
       throw ''
-        lib.fileset.fileFilter: First argument is of type ${typeOf predicate}, but it should be a function.''
+        lib.fileset.fileFilter: First argument is of type ${typeOf predicate}, but it should be a function instead.''
     else
       _fileFilter predicate
         (_coerce "lib.fileset.fileFilter: Second argument" fileset);
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix
index d55c84a395e..a4a230a4798 100644
--- a/lib/fileset/internal.nix
+++ b/lib/fileset/internal.nix
@@ -728,8 +728,12 @@ rec {
         _differenceTree (path + "/${name}") lhsValue (rhs.${name} or null)
       ) (_directoryEntries path lhs);
 
+  # Filters all files in a file set based on a predicate
+  # Type: ({ name, type, ... } -> Bool) -> FileSet -> FileSet
   _fileFilter = predicate: fileset:
     let
+      # Check the predicate for a path and a filesetTree, returning a new filesetTree
+      # Type: Path -> filesetTree -> filesetTree
       recurse = path: tree:
         mapAttrs (name: subtree:
           if isAttrs subtree || subtree == "directory" then
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh
index c1c67800f5e..4247c71efcf 100755
--- a/lib/fileset/tests.sh
+++ b/lib/fileset/tests.sh
@@ -785,6 +785,13 @@ checkFileset 'difference ./. ./b'
 
 ## File filter
 
+# The first argument needs to be a function
+expectFailure 'fileFilter null (abort "this is not needed")' 'lib.fileset.fileFilter: First argument is of type null, but it should be a function instead.'
+
+# The second argument can be a file set or an existing path
+expectFailure 'fileFilter (file: abort "this is not needed") null' 'lib.fileset.fileFilter: Second argument is of type null, but it should be a file set or a path instead.'
+expectFailure 'fileFilter (file: abort "this is not needed") ./a' 'lib.fileset.fileFilter: Second argument \('"$work"'/a\) is a path that does not exist.'
+
 # The predicate is not called when there's no files
 tree=()
 checkFileset 'fileFilter (file: abort "this is not needed") ./.'