lib.fileset.maybeMissing: init

This commit is contained in:
Silvan Mosberger
2023-11-07 01:04:13 +01:00
parent 5d08323dda
commit 1cc2c2f13d
4 changed files with 69 additions and 7 deletions

View File

@@ -11,6 +11,10 @@
Basics:
- [Implicit coercion from paths to file sets](#sec-fileset-path-coercion)
- [`lib.fileset.maybeMissing`](#function-library-lib.fileset.maybeMissing):
Create a file set from a path that may be missing.
- [`lib.fileset.trace`](#function-library-lib.fileset.trace)/[`lib.fileset.traceVal`](#function-library-lib.fileset.trace):
Pretty-print file sets for debugging.
@@ -105,6 +109,7 @@ let
_difference
_mirrorStorePath
_fetchGitSubmodulesMinver
_emptyWithoutBase
;
inherit (builtins)
@@ -148,6 +153,32 @@ let
in {
/*
Create a file set from a path that may or may not exist:
- If the path does exist, the path is [coerced to a file set](#sec-fileset-path-coercion).
- If the path does not exist, a file set containing no files is returned.
Type:
maybeMissing :: Path -> FileSet
Example:
# All files in the current directory, but excluding main.o if it exists
difference ./. (maybeMissing ./main.o)
*/
maybeMissing =
path:
if ! isPath path then
if isStringLike path then
throw ''
lib.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead.''
else
throw ''
lib.fileset.maybeMissing: Argument is of type ${typeOf path}, but it should be a path instead.''
else if ! pathExists path then
_emptyWithoutBase
else
_singleton path;
/*
Incrementally evaluate and trace a file set in a pretty way.
This function is only intended for debugging purposes.