haltcase / glob

Pure Nim library for matching file paths against Unix style glob patterns.
https://glob.bolingen.me
MIT License
61 stars 5 forks source link

[critical] walkGlob doesn't work with symlinks in pattern; unlike `ls`, `os.walkDir` etc #36

Closed timotheecour closed 4 years ago

timotheecour commented 4 years ago

/cc @citycide

say in /Users/timothee/temp/d18_D20200115T203454/ we have symlinks:

ls
total 0
drwxr-xr-x 4 timothee 128 Jan 15 20:43 bar1/
lrwxr-xr-x 1 timothee   4 Jan 15 20:43 bar2 -> bar1/
-rw-r--r-- 1 timothee   0 Jan 15 20:40 foo1.foo2.foo3.log
-rw-r--r-- 1 timothee   0 Jan 15 20:39 foo1.foo2.log
-rw-r--r-- 1 timothee   0 Jan 15 20:35 foo1.log
  import pkg/glob
  import std/os
  proc main()=
    # do `ln -s bar1 bar2` inside the dir
    let pattern2 = "/Users/timothee/temp/d18_D20200115T203454/bar2/*.log"
    echo "walkGlob:"
    for file1 in walkGlob(pattern2):
      echo (file1: file1)
    echo "walkFiles:"
    for file2 in walkFiles(pattern2):
      echo (file2: file2)

  main()

this produces:

walkGlob:
walkFiles:
(file2: "/Users/timothee/temp/d18_D20200115T203454/bar2/foo1.foo2.log")
(file2: "/Users/timothee/temp/d18_D20200115T203454/bar2/foo1.log")

note

this often occurs in practice, eg on OSX /tmp is a symlink to /private/tmp/:

realpath /tmp
/private/tmp

and walkGlob("/tmp/*.log") doesnt' return anything !

note

the returns files should keep the original name (eg /tmp/, not /private/tmp/), not the realpath names; as is done with all the tools including os.walkDir