summary refs log tree commit diff stats
path: root/lib/std/dirs.nim
diff options
context:
space:
mode:
authorAndrey Makarov <ph.makarov@gmail.com>2022-10-25 08:42:47 +0300
committerGitHub <noreply@github.com>2022-10-25 07:42:47 +0200
commit8ed2431db0d95bb30d69c563a137e348cd299621 (patch)
tree8ec35a56161b3c84b15c8ca1a84db8875e479c71 /lib/std/dirs.nim
parentc1343739e15eb2b225d8a523d577c0bc84148ad9 (diff)
downloadNim-8ed2431db0d95bb30d69c563a137e348cd299621.tar.gz
Implement Unix file regularity check (#20448) (#20628)
* Implement Unix file regularity check

* update std/dirs also
Diffstat (limited to 'lib/std/dirs.nim')
-rw-r--r--lib/std/dirs.nim32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/std/dirs.nim b/lib/std/dirs.nim
index e89bfc668..304075a6f 100644
--- a/lib/std/dirs.nim
+++ b/lib/std/dirs.nim
@@ -121,30 +121,33 @@ iterator walkDirs*(pattern: Path): Path {.tags: [ReadDirEffect].} =
   for p in walkDirs(pattern.string):
     yield Path(p)
 
-iterator walkDir*(dir: Path; relative = false, checkDir = false):
+iterator walkDir*(dir: Path; relative = false, checkDir = false,
+                 onlyRegular = false):
     tuple[kind: PathComponent, path: Path] {.tags: [ReadDirEffect].} =
   ## Walks over the directory `dir` and yields for each directory or file in
   ## `dir`. The component type and full path for each item are returned.
   ##
-  ## Walking is not recursive. If ``relative`` is true (default: false)
-  ## the resulting path is shortened to be relative to ``dir``.
-  ##
-  ## If `checkDir` is true, `OSError` is raised when `dir`
-  ## doesn't exist.
-  for (k, p) in walkDir(dir.string, relative, checkDir):
+  ## Walking is not recursive.
+  ## * If `relative` is true (default: false)
+  ##   the resulting path is shortened to be relative to ``dir``,
+  ##   otherwise the full path is returned.
+  ## * If `checkDir` is true, `OSError` is raised when `dir`
+  ##   doesn't exist.
+  ## * If `onlyRegular` is true, then (besides all directories) only *regular*
+  ##   files (**without** special "file" objects like FIFOs, device files,
+  ##   etc) will be yielded on Unix.
+  for (k, p) in walkDir(dir.string, relative, checkDir, onlyRegular):
     yield (k, Path(p))
 
 iterator walkDirRec*(dir: Path,
                      yieldFilter = {pcFile}, followFilter = {pcDir},
-                     relative = false, checkDir = false): Path {.tags: [ReadDirEffect].} =
+                     relative = false, checkDir = false, onlyRegular = false):
+                    Path {.tags: [ReadDirEffect].} =
   ## Recursively walks over the directory `dir` and yields for each file
   ## or directory in `dir`.
   ##
-  ## If ``relative`` is true (default: false) the resulting path is
-  ## shortened to be relative to ``dir``, otherwise the full path is returned.
-  ##
-  ## If `checkDir` is true, `OSError` is raised when `dir`
-  ## doesn't exist.
+  ## Options `relative`, `checkdir`, `onlyRegular` are explained in
+  ## [walkDir iterator] description.
   ##
   ## .. warning:: Modifying the directory structure while the iterator
   ##   is traversing may result in undefined behavior!
@@ -173,5 +176,6 @@ iterator walkDirRec*(dir: Path,
   ## * `walkFiles iterator`_
   ## * `walkDirs iterator`_
   ## * `walkDir iterator`_
-  for p in walkDirRec(dir.string, yieldFilter, followFilter, relative, checkDir):
+  for p in walkDirRec(dir.string, yieldFilter, followFilter, relative,
+                      checkDir, onlyRegular):
     yield Path(p)