mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
lib.fileset.fileFilter: Minor cleanups and more tests
This commit is contained in:
parent
f3565a2c08
commit
e1d8331738
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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") ./.'
|
||||
|
|
Loading…
Reference in a new issue