Skip to content

Commit

Permalink
fix: handle symlinks correctly, closes #36 (#38)
Browse files Browse the repository at this point in the history
* fix #36; correctness wrt symlinks

* fix tests
  • Loading branch information
timotheecour authored and haltcase committed Jan 20, 2020
1 parent 28e5f93 commit 068369b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/glob.nim
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ iterator initStack (
template push (path: string) =
var kind: PathComponent
if path.pathType(kind) and kind in kinds:
yield (path.expandFilename, kind)
yield (path.absolutePath, kind)

let normalized =
when FileSystemCaseSensitive:
Expand Down
16 changes: 11 additions & 5 deletions tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ else:

import os
from algorithm import sortedByIt
from sequtils import toSeq
from strutils import split
from sequtils import toSeq, mapIt
from strutils import split, toLower

import unittest

Expand Down Expand Up @@ -36,8 +36,12 @@ proc createStructure (dir: string, files: seq[string]): () -> void =

result = () => removeDir(dir)

proc seqsEqual (seq1, seq2: seq[string]): bool =
seq1.sortedByIt(it) == seq2.sortedByIt(it)

proc seqsEqual (seq1, seq2: seq[string], ignoreCase = false): bool =
if ignoreCase:
seqsEqual(seq1.mapIt(toLower(it)), seq2.mapIt(toLower(it)))
else:
seq1.sortedByIt(it) == seq2.sortedByIt(it)

suite "globToRegex":
test "produces equivalent regular expressions":
Expand Down Expand Up @@ -377,12 +381,14 @@ suite "pattern walking / listing":

test "`IgnoreCase` enables case insensitive matching":
let o = defaultGlobOptions + {IgnoreCase}
# see https://stackoverflow.com/questions/59797065/how-to-get-original-case-of-a-path-on-osx-eg-tmp-tmp
# maybe there is a better way
check seqsEqual(toSeq(walkGlob("TEMP/**", options = o)), @[
p"temp/deep/dir/file.nim",
p"temp/not_as/deep.jpg",
p"temp/not_as/deep.nim",
p"temp/shallow.nim"
])
], ignoreCase = true)

when FileSystemCaseSensitive:
test "`IgnoreCase` works correctly on the glob base":
Expand Down

0 comments on commit 068369b

Please sign in to comment.