Skip to content

Commit

Permalink
Add checkError parameter to os.walkDirRec
Browse files Browse the repository at this point in the history
  • Loading branch information
demotomohiro committed Jan 10, 2020
1 parent b2f8bde commit ce562c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
and `typetraits.get` to get the ith element of a type tuple.
- Added `typetraits.genericParams` to return a tuple of generic params from a generic instantiation

- Added `checkError` parameter to `os.walkDir`. If it is true, raises `OSError`
when `dir` cannot be open.
- Added `checkError` parameter to `os.walkDir` and `os.walkDirRec`.
If it is true, raises `OSError` when `dir` cannot be open.

## Library changes

Expand Down
8 changes: 6 additions & 2 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,8 @@ iterator walkDir*(dir: string;

iterator walkDirRec*(dir: string,
yieldFilter = {pcFile}, followFilter = {pcDir},
relative = false): string {.tags: [ReadDirEffect].} =
relative = false,
checkError = false): string {.tags: [ReadDirEffect].} =
## Recursively walks over the directory `dir` and yields for each file
## or directory in `dir`.
##
Expand Down Expand Up @@ -2096,6 +2097,9 @@ iterator walkDirRec*(dir: string,
## ``pcLinkToDir`` follow symbolic links to directories
## --------------------- ---------------------------------------------
##
## When `dir` or any directory in `dir` cannot be open, raises `OSError`
## if `checkError` is true, otherwise the error is ignored and yield nothing
## from the directory.
##
## See also:
## * `walkPattern iterator <#walkPattern.i,string>`_
Expand All @@ -2106,7 +2110,7 @@ iterator walkDirRec*(dir: string,
var stack = @[""]
while stack.len > 0:
let d = stack.pop()
for k, p in walkDir(dir / d, relative = true):
for k, p in walkDir(dir / d, relative = true, checkError):
let rel = d / p
if k in {pcDir, pcLinkToDir} and k in followFilter:
stack.add rel
Expand Down

0 comments on commit ce562c6

Please sign in to comment.