-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow traversal of symlinks in glob #2134
Conversation
I should also note that I'm unsure how well |
Your intuition was correct - minimatch expects paths to be joined with |
Good looking out. |
I confirmed it myself: this doesn't work on Windows. 😄 Will get it working |
(FWIW, the "glob handles root match" test fails on Windows in |
1a01a0d
to
804e5a9
Compare
Closes TypeStrong#2130 This adds a `followSymlinks` option to the `glob()` function, and enables it when searching for entry points. If `true`, and a symbolic link is encountered, a stat will be taken of the symlink's target. If a dir or file, the symlink is handled like any other dir or file. If a symbolic link itself (symlink to a symlink), we take a stat of the next until we find a dir or file, then handle it. There is a little bit of caching to avoid extra I/O, and protection from recursive symlinks. However, it's possible (though unlikely) that the FS could cause a "max call stack exceeded" exception. If someone runs into this, we can change the implementation to a loop instead of a recursive function. Apologies for blasting the `do..while`. I love a good `do` myself, but splitting out the lambda functions make it untenable.
804e5a9
to
6c1b4ac
Compare
OK, I have the tests passing in Windows (Win 10, PowerShell). The code itself was fine, but the tests made poor assumptions. The test fix I made for an unrelated failure on Windows (6c1b4ac) is dubious and I think it'd necessitate a PR into typestrong/fs-fixture-builder to correct the underlying problem. What I was seeing was that |
That's fun, the normalize is a good idea anyways - I'd rather not care what separators |
Thanks! |
Closes #2130
This adds a
followSymlinks
option to theglob()
function, and enables it when searching for entry points.If
true
, and a symbolic link is encountered, a stat will be taken of the symlink's target. If a dir or file, the symlink is handled like any other dir or file. If a symbolic link itself (symlink to a symlink), we take a stat of the next until we find a dir or file, then handle it.There is a little bit of caching to avoid extra I/O, and protection from recursive symlinks. However, it's possible (though unlikely) that the FS could cause a "max call stack exceeded" exception. If someone runs into this, we can change the implementation to a loop instead of a recursive function.
Apologies for blasting the
do..while
. I love a gooddo
myself, but splitting out the lambda functions make it untenable.