soldair / node-walkdir

Walk a directory tree emitting events based on the contents. API compatable with node-findit. Walk a tree of any depth. Fast! Handles permission errors. Stoppable. windows support. Pull requests are awesome. watchers are appreciated.
MIT License
130 stars 22 forks source link

Follow symlinks, but don't follow them twice in case of loops? #23

Closed CoDEmanX closed 9 years ago

CoDEmanX commented 9 years ago

Reading the description, there doesn't seem to be a built-in way to follow symlinks while detecting cycles and prevent infinite loops. I guess one could keep track of all encountered symlinks and ignore() them if they've been encountered before. It would still be nice to have this feature built-in, because it's a sensible default (would you ever want to follow a symlink twice?!)

soldair commented 9 years ago

Its cycle safe even with links.

see here. https://github.com/soldair/node-walkdir/blob/master/walkdir.js#L79

by the time it hits this line the symlink has be resolved to its actual path. if we have seen it already we stop recursing and dont emit it.

soldair commented 9 years ago

added a cycle to the unit test fixture to make sure this stays covered. https://github.com/soldair/node-walkdir/commit/e4a6f51e60c196dff68def96999290b7fb7c8ec2

CoDEmanX commented 9 years ago

Perfect, thanks!