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: avoid endless loop when handling symlinks #108 #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

q0rban
Copy link

@q0rban q0rban commented Oct 21, 2024

This resolves #108 for me. I tried to run tests locally to see if this breaks anything, but I guess the tests need to run in CI as they were failing with or without this change on my environment.

@robertsLando
Copy link
Member

@q0rban I'm not sure that just removing code is the correct way to handle this. You should handle the case of infinite loop like keeping track of paths to be sure you don't hit the same path twice to break the loop

@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

The interesting thing is that the code is already keeping track of the paths. I couldn't figure out a scenario where this code wouldn't result in an infinite loop, which is why I deleted it. But then I realize it is assuming that the paths are not nested at the same level. So I believe the code will work if path/to/some/symlink/index.js is symlinked to path/to/real/index.js (since they have different nesting levels), but I believe it will always loop if path/to/symlink/index.js is linked to path/to/real/index.js since they have the same nesting depth.

Furthermore, I don't believe this function will properly handle the scenario where there are multiple symlinks involved. For example, let's say module chicken is symlinked wholesale into another module:

path/to/node_modules/some-module/node_modules/symchicken -> path/to/node_modules/some-module/node_modules/chicken

but then, what happens if chicken has some links in it as well?

chicken/lib/link.js -> chicken/deeply/nested/index.js

This would result in

path/to/node_modules/some-module/node_modules/symchicken/lib/index.js -> path/to/node_modules/some-module/node_modules/chicken/deeply/nested/index.js

Does that mean this logic needs to recurse? The mind reels.

@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

Incidentally, do you have any tips on running tests locally? I don't see any documentation on that in the repo.

realFile = a.realFile;
} catch (error) {
log.error((error as Error).message);
return;
Copy link
Author

@q0rban q0rban Oct 22, 2024

Choose a reason for hiding this comment

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

Should this fail gracefully like this, or should we not handle the error here?

@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

@robertsLando updated the approach and would appreciate your thoughts. The existing logic seems error prone, and thus difficult to ascertain the intent of it.

@robertsLando
Copy link
Member

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.

Problem with symlinks inside node_modules
2 participants