-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
fs: add followSymlinks option to glob and globSync #61317
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
base: main
Are you sure you want to change the base?
fs: add followSymlinks option to glob and globSync #61317
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61317 +/- ##
==========================================
- Coverage 88.54% 88.52% -0.03%
==========================================
Files 704 704
Lines 208753 208796 +43
Branches 40283 40285 +2
==========================================
- Hits 184849 184835 -14
- Misses 15907 15979 +72
+ Partials 7997 7982 -15
🚀 New features to boost your workflow:
|
|
|
||
| describe('glob follow', () => { | ||
| test('should return matched files in symlinked directory when follow is true', async () => { | ||
| if (common.isWindows) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why we completely bail on this test if we're on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup function excluded it specifically as well. I did not question why.
From what I am understanding, symlinks need admin permissions or developer mode enabled on Windows which is perhaps why the test does not exist for it.
| * `followSymlinks` {boolean} `true` to traverse matching symbolic links to directories, | ||
| `false` otherwise. **Default:** `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to update the changes entry above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be the version tag for the change?
| const { lstatSync, readdirSync, statSync: fsStatSync } = require('fs'); | ||
| const { lstat, readdir, stat: fsStat } = require('fs/promises'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these being renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that was for my reference. I will rename and push. Sorry!
I won't be pushing. Many locations in the file refer to a variable named stat. keeping the function name as the same would reduce readability.
If you believe that I should make the change, do let me know, I'll commit and push ASAP :)
lib/internal/fs/glob.js
Outdated
| try { | ||
| const stat = fsStatSync(join(fullpath, entry.name)); | ||
| isDirectory = stat.isDirectory(); | ||
| } catch { | ||
| // ignore | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't an error here be bubbled up? If the user explicitly asked for us to follow symlinks, and we can't do that, wouldn't they expect some kind of indication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should inform the user. Sorry for the oversight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should emit a warning or an error would be more appropriate? I believe an error is better.
e611924 to
7b0c22d
Compare
This PR adds a
followSymlinksoption tofs.globandfs.globSync, allowing recursive directory traversal into symbolic links when enabled.Changes
lib/internal/fs/glob.js:followSymlinkstoGlobconstructor options.Globclass to handlefollowSymlinks: true.statwhenfollowSymlinksis enabled. If the symlink points to a directory, it is now traversed.doc/api/fs.md.test/parallel/test-fs-glob.mjsto verifyfollowSymlinks: truebehavior.Fixes: #61033