minor fix to Posix part of walkDir (#16234)
* change break->continue and rewrite one-yield-style * use case statement for clarity * Tiny nit Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
c731f7ab14
commit
e223a05123
1 changed files with 18 additions and 12 deletions
|
|
@ -2120,21 +2120,27 @@ iterator walkDir*(dir: string; relative = false, checkDir = false):
|
||||||
y = path
|
y = path
|
||||||
var k = pcFile
|
var k = pcFile
|
||||||
|
|
||||||
|
template kSetGeneric() = # pure Posix component `k` resolution
|
||||||
|
if lstat(path, s) < 0'i32: continue # don't yield
|
||||||
|
elif S_ISDIR(s.st_mode):
|
||||||
|
k = pcDir
|
||||||
|
elif S_ISLNK(s.st_mode):
|
||||||
|
k = getSymlinkFileKind(path)
|
||||||
|
|
||||||
when defined(linux) or defined(macosx) or
|
when defined(linux) or defined(macosx) or
|
||||||
defined(bsd) or defined(genode) or defined(nintendoswitch):
|
defined(bsd) or defined(genode) or defined(nintendoswitch):
|
||||||
if x.d_type != DT_UNKNOWN:
|
case x.d_type
|
||||||
if x.d_type == DT_DIR: k = pcDir
|
of DT_DIR: k = pcDir
|
||||||
if x.d_type == DT_LNK:
|
of DT_LNK:
|
||||||
if dirExists(path): k = pcLinkToDir
|
if dirExists(path): k = pcLinkToDir
|
||||||
else: k = pcLinkToFile
|
else: k = pcLinkToFile
|
||||||
yield (k, y)
|
of DT_UNKNOWN:
|
||||||
continue
|
kSetGeneric()
|
||||||
|
else: # e.g. DT_REG etc
|
||||||
|
discard # leave it as pcFile
|
||||||
|
else: # assuming that field `d_type` is not present
|
||||||
|
kSetGeneric()
|
||||||
|
|
||||||
if lstat(path, s) < 0'i32: break
|
|
||||||
if S_ISDIR(s.st_mode):
|
|
||||||
k = pcDir
|
|
||||||
elif S_ISLNK(s.st_mode):
|
|
||||||
k = getSymlinkFileKind(path)
|
|
||||||
yield (k, y)
|
yield (k, y)
|
||||||
|
|
||||||
iterator walkDirRec*(dir: string,
|
iterator walkDirRec*(dir: string,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue