fastwalk directories vs files
lrstanley opened this issue · 2 comments
Running into an issue where fastwalk is saying a file is actually a directory. After further investigation, it looks like I'm misusing the library (passing in a file initially, rather than a directory).
However, I didn't notice it at first, because the walk function was still being called, which I don't think it really should have been.
https://github.com/mattn/go-zglob/blob/master/fastwalk/fastwalk.go#L162
Specifically, it looks like you aren't doing the initial stat on the directory, just passing in the standard ModeDir..
Looking at the standard library implementation, which supports getting passed a file, I think that fastwalk should as well. Specifically: when fastwalk initializes, stat that file/dir. If it's a file, execute the walkFn and return. Only run it on the initial dir/file, and not subsequent, otherwise the point of the fastwalk would be pointless.
Thank you. Could you please add test?
Tests added, and squashed into existing commit.