Skip to content

Commit c416e22

Browse files
committed
fix useLstat & stylistic changes
1 parent b0db5df commit c416e22

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/pure/os.nim

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ type OpenDirStatus* = enum
20062006
type WalkStepKind* = enum
20072007
wsOpenDir, ## attempt to open directory
20082008
wsEntryOk, ## the entry is OK
2009-
wsEntryBad ## usually a dangling symlink on posix, so unclear if it
2009+
wsEntryBad ## usually a dangling symlink on posix, when it's unclear if it
20102010
## points to a file or directory
20112011
wsInterrupted ## the directory handle got invalidated during reading
20122012

@@ -2023,9 +2023,17 @@ type WalkStep = ref object
20232023

20242024
iterator tryWalkDir*(dir: string; relative=false): WalkStep {.
20252025
tags: [ReadDirEffect], raises: [].} =
2026-
## An analogue of `walkDir iterator <#walkDir.i,string>`_ with full error
2027-
## checking. Yields "steps" of walking through `dir`, each step contains its path `path`, OS error code `code` and additional info. At first step yields info with the status of opening `dir` as a directory, tag `wsOpenDir`. If it's OK,
2028-
## the subsequent steps will yield the directory entries with file/directory type as info, tag `wsEntryOk`. Dangling symlinks on posix are reported as wsEntryBad. If (rarely) walking terminates with an error, tag is `wsInterrupted`.
2026+
## A version of `walkDir iterator <#walkDir.i,string>`_ with more
2027+
## thorough error checking.
2028+
## Yields *steps* of walking through `dir`, each step contains
2029+
## its path ``path``, OS error code ``code`` and additional tag ``kind``.
2030+
## At first step it yields info ``openStatus`` of opening
2031+
## status `dir` as a directory, tag ``wsOpenDir``.
2032+
## If it's OK, the subsequent steps will yield the directory entries
2033+
## with component type as info ``entryType``, tag ``wsEntryOk``.
2034+
## Dangling symlinks on posix are reported as ``wsEntryBad``.
2035+
## If (rarely) walking terminates with an error (such as an I/O error),
2036+
## tag is `wsInterrupted`.
20292037
##
20302038
## .. code-block:: Nim
20312039
## for step in tryWalkDir("dirA"):
@@ -2038,7 +2046,7 @@ iterator tryWalkDir*(dir: string; relative=false): WalkStep {.
20382046
## of odAccessDenied: echo dir & " - Access Denied" & err
20392047
## of odNotFound: echo dir & " - no such path" & err
20402048
## of odUnknownError: echo dir & "unknown error - that's bad!" & err
2041-
## of wsEntryOk: echo step.path & " is entry of kind " & $step.entryType
2049+
## of wsEntryOk: echo step.path & " is entry of kind " & $step.entryType
20422050
## of wsEntryBad: echo step.path & " is broken symlink " & err
20432051
## of wsInterrupted:
20442052
## echo dir & " traversal interrupted, really bad! " & err
@@ -2151,7 +2159,7 @@ iterator tryWalkDir*(dir: string; relative=false): WalkStep {.
21512159
y = path
21522160
var k = pcFile
21532161

2154-
var use_lstat = false
2162+
var useLstat = false
21552163
when defined(linux) or defined(macosx) or
21562164
defined(bsd) or defined(genode) or defined(nintendoswitch):
21572165
if x.d_type != DT_UNKNOWN:
@@ -2168,12 +2176,12 @@ iterator tryWalkDir*(dir: string; relative=false): WalkStep {.
21682176
res = sGetError(wsEntryBad, y)
21692177
else:
21702178
res = sNoErrors(k, y)
2171-
use_lstat = false
2179+
useLstat = false
21722180
else:
2173-
use_lstat = true
2181+
useLstat = true
21742182
else:
2175-
use_lstat = true
2176-
if use_lstat:
2183+
useLstat = true
2184+
if useLstat:
21772185
# special case of DT_UNKNOWN: some filesystems can't detect that
21782186
# entry is a directory and keep its d_type as 0=DT_UNKNOWN
21792187
if lstat(path, s) < 0'i32:

0 commit comments

Comments
 (0)