summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authoralaviss <alaviss@users.noreply.github.com>2018-12-21 20:12:48 +0700
committerAndreas Rumpf <rumpf_a@web.de>2018-12-21 14:12:48 +0100
commitb6257f3f212036216fb4aeb521a3d120222b237c (patch)
tree37738cd9a0ed5f080c1b0e607c9a0f209c5cc84e /lib/pure
parent52e36a19a902edcc533c0e0ffd0eff8c83158fef (diff)
downloadNim-b6257f3f212036216fb4aeb521a3d120222b237c.tar.gz
os.walkDir: correctly evaluate paths when relative = true (#10057) [backport]
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/os.nim9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 2919b39f0..330d2d6b8 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1512,8 +1512,9 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
             var y = $x.d_name.cstring
           if y != "." and y != "..":
             var s: Stat
+            let path = dir / y
             if not relative:
-              y = dir / y
+              y = path
             var k = pcFile
 
             when defined(linux) or defined(macosx) or
@@ -1521,16 +1522,16 @@ iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path:
               if x.d_type != DT_UNKNOWN:
                 if x.d_type == DT_DIR: k = pcDir
                 if x.d_type == DT_LNK:
-                  if dirExists(y): k = pcLinkToDir
+                  if dirExists(path): k = pcLinkToDir
                   else: k = pcLinkToFile
                 yield (k, y)
                 continue
 
-            if lstat(y, s) < 0'i32: break
+            if lstat(path, s) < 0'i32: break
             if S_ISDIR(s.st_mode):
               k = pcDir
             elif S_ISLNK(s.st_mode):
-              k = getSymlinkFileKind(y)
+              k = getSymlinkFileKind(path)
             yield (k, y)
 
 iterator walkDirRec*(dir: string,