check ERROR_NO_MORE_FILES to prevent walkDir[Rec] to quit prematurely

This commit is contained in:
oskca
2018-01-10 23:20:18 +08:00
parent d0a9fac362
commit e98a2051ce

View File

@@ -672,7 +672,7 @@ template walkCommon(pattern: string, filter) =
if dotPos < 0 or idx >= ff.len or ff[idx] == '.' or
pattern[dotPos+1] == '*':
yield splitFile(pattern).dir / extractFilename(ff)
if findNextFile(res, f) == 0'i32: break
if findNextFile(res, f) == 0'i32 and getLastError() == 18: break # ERROR_NO_MORE_FILES=18
else: # here we use glob
var
f: Glob
@@ -782,7 +782,7 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
let xx = if relative: extractFilename(getFilename(f))
else: dir / extractFilename(getFilename(f))
yield (k, xx)
if findNextFile(h, f) == 0'i32: break
if findNextFile(h, f) == 0'i32 and getLastError() == 18: break # ERROR_NO_MORE_FILES=18
else:
var d = opendir(dir)
if d != nil: