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

glob patterns like "*/z1.txt" don't work (ie when a glob happens before / it seems) #29

Closed timotheecour closed 6 years ago

timotheecour commented 6 years ago

/cc @citycide this bug seems serious:

on linux:

find pwd /tmp/d03 /tmp/d03/A1 /tmp/d03/A1/z2.txt /tmp/d03/A1/Z2.txt /tmp/d03/a1 /tmp/d03/a1/z1.txt

echo toSeq(walkGlob("a1/z1.txt"))
@["a1/z1.txt"]
echo toSeq(walkGlob("*/z1.txt"))
@[] # BUG
echo toSeq(walkGlob("a?/z1.txt"))
@[]  # BUG
echo toSeq(walkGlob("a?/z?.txt"))
@[]  # BUG
timotheecour commented 6 years ago

@citycide can we reopen? still doesn't work properly: in example above, do: cd ..

ls */*/z1.txt
d03/a1/z1.txt  d04/a1/z1.txt
import glob,sequtils
echo toSeq(walkGlob("*/*/z1.txt"))
@[]
timotheecour commented 6 years ago

@citycide friendly ping :) this bug really limits usability of this otherwise excellent tool ...

haltcase commented 6 years ago

Yeah I'm working on it but it hasn't been as simple as I thought it would be. Still in progress.

timotheecour commented 6 years ago

@citycide can you adapt https://github.com/git/git/blob/master/wildmatch.c to Nim (either via importc or via manual conversion, maybe starting gradually, starting from importc)? that seems like exactly what we want

top-level glob can use it as a building block; and we can implement BFS/DFS search on top of that. this is exactly what I did in my own (private... but I can revive and share it if needed) glob function for D

happy to discuss implementation details; but I think it could make sense to start from importc to reuse code, incorporate it in higher level wrappers, and (in a later stage, if needed), gradually convert importc to nim

haltcase commented 6 years ago

@timotheecour that doesn't support extended glob features like {} groups and patterns. It's also not the problem area: matching works fine as-is, it's the file system traversal that is difficult because we need to partially match directories along the way.

data-man commented 6 years ago

doesn't support extended glob features like {} groups and patterns

Exactly! So I prefer filename_match from FLTK.