about summary refs log tree commit diff
path: root/lib/filesystem.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-04-05 17:16:10 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-05-22 14:13:57 +0200
commit84a3d633d6f3653675d794ef5e8e90bf0cb7c502 (patch)
tree125c7e27b8776b258d4eedcbf409514a038960fa /lib/filesystem.nix
parentd064d972f07b908db3efb909d6663bee3adf8d40 (diff)
lib.filesystem.pathType and co.: Improve documentation
Diffstat (limited to 'lib/filesystem.nix')
-rw-r--r--lib/filesystem.nix43
1 files changed, 40 insertions, 3 deletions
diff --git a/lib/filesystem.nix b/lib/filesystem.nix
index db120a48c64be..6dfd273b0a55a 100644
--- a/lib/filesystem.nix
+++ b/lib/filesystem.nix
@@ -19,7 +19,18 @@ in
 {
 
   /*
-    Returns the type of a path: regular (for file), symlink, or directory.
+    The type of a path. The path needs to exist and be accessible.
+    The result is either "directory" for a directory, "regular" for a regular file, "symlink" for a symlink, or "unknown" for anything else.
+
+    Type:
+      pathType :: Path -> String
+
+    Example:
+      pathType /.
+      => "directory"
+
+      pathType /some/file.nix
+      => "regular"
   */
   pathType = path:
     if ! pathExists path
@@ -34,13 +45,39 @@ in
     else (readDir (dirOf path)).${baseNameOf path};
 
   /*
-    Returns true if the path exists and is a directory, false otherwise.
+    Whether a path exists and is a directory.
+
+    Type:
+      pathIsDirectory :: Path -> Bool
+
+    Example:
+      pathIsDirectory /.
+      => true
+
+      pathIsDirectory /this/does/not/exist
+      => false
+
+      pathIsDirectory /some/file.nix
+      => false
   */
   pathIsDirectory = path:
     pathExists path && pathType path == "directory";
 
   /*
-    Returns true if the path exists and is a regular file, false otherwise.
+    Whether a path exists and is a regular file, meaning not a symlink or any other special file type.
+
+    Type:
+      pathIsRegularFile :: Path -> Bool
+
+    Example:
+      pathIsRegularFile /.
+      => false
+
+      pathIsRegularFile /this/does/not/exist
+      => false
+
+      pathIsRegularFile /some/file.nix
+      => true
   */
   pathIsRegularFile = path:
     pathExists path && pathType path == "regular";