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

Does not get symbolic links created from "npm link" #24

Closed leslc closed 8 years ago

leslc commented 8 years ago

Thanks @soldair for walkdir.

I wanted to bring up an edge case. "walkdir" does not return a subdirectory that is a symbolic linked created by "npm link".

With "npm link", there are two symbolic links:

/project/node_modules/MODULEDIR  ->  /usr/local/lib/node_modules/MODULEDIR
/usr/local/lib/node_modules/MODULEDIR -> /code/MODULEDIR

Ultimately, I'd like to traverse the files in the directory "/code/MODULEDIR". Is walkdir limited to resolving the symlink one level deep?

Thanks

soldair commented 8 years ago

It should work. If it doesn't you found a bug :).

I have tested this with nested symlinks before so very interesting. I assume you set follow symlinks?

One thing to note is it will only ever emit a path once. Even if it's linked from multiple places.

I'll check into this regression and sort it out unless you beat me to it. On Oct 14, 2015 5:38 PM, "leslc" notifications@github.com wrote:

Thanks @soldair https://github.com/soldair for walkdir.

I wanted to bring up an edge case. "walkdir" does not return a subdirectory that is a symbolic linked created by "npm link".

With "npm link", there are two symbolic links:

/project/node_modules/MODULENAME -> /usr/local/lib/node_modules/MODULENAME /usr/local/lib/node_modules/MODULENAME -> /code/MODULENAME

Ultimately, I'd like to traverse the files in "/code/MODULENAME". Is walkdir limited to resolving the symlink one level deep?

Thanks

— Reply to this email directly or view it on GitHub https://github.com/soldair/node-walkdir/issues/24.

soldair commented 8 years ago

lets see i tried to make a test case to capture the bug you reported but i couldn't get it to fail. =/

https://github.com/soldair/node-walkdir/blob/master/test/nested-symlink.js

is follows a link to a link to a file called found-me. any ideas about how i can do this better?

leslc commented 8 years ago

@soldair, thanks for checking this out. Sorry, my bad for not looking closer, the symlink IS being followed. My issue is the code is expecting the original filename instead the resolved filename.

For example:

/symlinkdir/filenameA -> /truelocation/filenameB

Expected filename "/symlinkdir/filenameA" to be returned, but get "/truelocation/filenameB" instead.

Is it possible to have an option to return the original filename of the symlink? (If you point me towards the right areas of the code, I can attempt to add this as a PR).

soldair commented 8 years ago

i'll think about this a little more. you could maybe use data in link events to make these paths. as long as we have the true resolved path we can make sure to avoid implementing infinitely long paths...

let me see if i understand you correctly.

if i have a directory structure like

/a/mymodule/file
/b/anothermodule/node_modules/mymodule -> /a/mymodule

you want to configure walkdir to emit these paths when you walkdir('/b')

/b/anothermodule
/b/anothermodule/node_modules
/b/anothermodule/node_modules/mymodule
/b/anothermodule/node_modules/mymodule/file

instead of

/b/anothermodule
/b/anothermodule/node_modules
/b/anothermodule/node_modules/mymodule
/a/mymodule/file

remember walkdir also will never emit the same file twice so if it find to links to the same file the second is never emitted because its a duplicate. this prevents all manner of infinite recursion bugs

leslc commented 8 years ago

Yes on the example you gave. Possibly add a new option? Eg. "symlink_name = symlink | source" (defaults to "source" for current behavior).

leslc commented 8 years ago

FYI, I decided to abandon the symbolic link idea and try something else. I'll close this.

soldair commented 8 years ago

OK good luck. On Nov 3, 2015 5:08 PM, "leslc" notifications@github.com wrote:

FYI, I decided to abandon the symbolic link idea and try something else. I'll close this.

— Reply to this email directly or view it on GitHub https://github.com/soldair/node-walkdir/issues/24#issuecomment-153504773 .