Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other languages #13642

Merged
merged 8 commits into from
Mar 20, 2020
Next Next commit
walkDir now throws if input dir invalid
timotheecour committed Mar 19, 2020
commit a6b054315795cfb5c8cf0b202f678c73cc307f31
7 changes: 4 additions & 3 deletions compiler/nimblecmd.nim
Original file line number Diff line number Diff line change
@@ -121,9 +121,10 @@ proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
var packages = newStringTable(modeStyleInsensitive)
var pos = dir.len-1
if dir[pos] in {DirSep, AltSep}: inc(pos)
for k,p in os.walkDir(dir):
if k == pcDir and p[pos] != '.':
addPackage(conf, packages, p, info)
if dir.existsDir:
for k,p in os.walkDir(dir):
if k == pcDir and p[pos] != '.':
addPackage(conf, packages, p, info)
for p in packages.chosen:
addNimblePath(conf, p, info)

4 changes: 3 additions & 1 deletion lib/pure/os.nim
Original file line number Diff line number Diff line change
@@ -2087,7 +2087,9 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
else: raiseOSError(errCode.OSErrorCode)
else:
var d = opendir(dir)
if d != nil:
if d == nil:
raiseOSError(osLastError(), dir)
else:
defer: discard closedir(d)
while true:
var x = readdir(d)