Skip to content
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: Don't follow circular symlinks #126

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

joshhunt
Copy link
Contributor

@joshhunt joshhunt commented Mar 31, 2024

Fixes the Error: ELOOP: too many symbolic links encountered exception that happens during the walkdir when the working directory contains circular symlinks.

I think this is the right logic to check this, and added some tests to try and catch the common scenarios.

@phated
Copy link
Member

phated commented Mar 31, 2024

@joshhunt could we just check if the error is ELoop and bail?

@joshhunt
Copy link
Contributor Author

joshhunt commented Apr 2, 2024

@phated Could do. However, I think that's problematic because:

  • I don't think we want to throw an error on circular symlinks, as some people will have these for legitimate reasons, and with no way to filter out directories from the walkdir this would just not work if you have them
  • it wastes time needlessly walking through the circular symlinks
  • it would emit the same file multiple times through each 'step' of the circular symlink - e.g fixtures/folderA/file-a.txt, fixtures/folderA/dest/folderA/file-a.txt, fixtures/folderA/dest/folderA/dest/folderA/file-a.txt, etc

It's up to you which you would prefer, but I'm skeptical of just waiting for ELOOP.

I think the logic in this PR is good, but I'm struggling to come up with additional test cases to better validate it...

@joshhunt joshhunt marked this pull request as ready for review April 6, 2024 10:48
@joshhunt
Copy link
Contributor Author

joshhunt commented Apr 6, 2024

@phated I think this is in a good spot - open for feedback, other approaches, or scenarios to test!

Comment on lines +792 to +799
// And it should follow a symlink to a parent directory (circular symlink) without blowing up
{
cwd: dir,
base: dir + '/fixtures/symlinks',
path:
dir +
'/fixtures/symlinks/symlink-dest/hey/isaidhey/whatsgoingon/test.txt',
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check if this is a duplicate glob getting through because we wouldn't want to emit it twice.

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joshhunt! I'm going to merge this and then do some cleanup to integrate it with my changes to avoid blowing the stack.

@phated phated merged commit cf8b197 into gulpjs:master Apr 8, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants