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

symlinks interact badly with Dir; cause infinite loop/recursion #364

Closed
smparkes opened this Issue Oct 29, 2012 · 4 comments

Comments

Projects
None yet
6 participants
@smparkes
Copy link
Contributor

smparkes commented Oct 29, 2012

There seems to be a symlink corner case that causes Dir expansion to infinitely loop/recur. In the test case, two multiply nested directories contain symbolic links back to their shared parent.

My test case is a directory named objc. The ls -LR contents are

~/objc ls -lR
total 0
drwxr-xr-x  3 smparkes  smparkes  102 Oct 29 13:12 examples

./examples:
total 0
drwxr-xr-x  4 smparkes  smparkes  136 Oct 29 13:13 osx

./examples/osx:
total 0
drwxr-xr-x  3 smparkes  smparkes  102 Oct 29 13:14 bare
drwxr-xr-x  3 smparkes  smparkes  102 Oct 29 13:13 demo

./examples/osx/bare:
total 8
lrwxr-xr-x  1 smparkes  smparkes  16 Sep 27 16:32 objc -> ../../../../objc

./examples/osx/demo:
total 8
lrwxr-xr-x  1 smparkes  smparkes  16 Sep 27 16:32 objc -> ../../../../objc

Should be able to create it with (bash)

mkdir -p objc/osx/{bare,demo}
ln -s ../../../../objc objc/osx/bare
ln -s ../../../../objc objc/osx/demo

Then running ruby -e 'p Dir["**/*.o"]' never returns.

Tested on 1.6.8 and 1.7.0.

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Dec 6, 2012

JVM does not handle symbolic links well. I suspect that this is a manifestation of that issue.

@the8472

This comment has been minimized.

Copy link
Contributor

the8472 commented Dec 10, 2012

nio.2 has an API for directory tree walking that can ignore symbolic links:

http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.util.Set,%20int,%20java.nio.file.FileVisitor)

By default, symbolic links are not automatically followed by this method. If the options parameter contains the FOLLOW_LINKS option then symbolic links are followed.

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Sep 3, 2013

We are still supporting Java 6, so we can't use nio.2 yet. Probably 9k.

@MSNexploder

This comment has been minimized.

Copy link
Contributor

MSNexploder commented Jan 9, 2014

Just retested using JRuby 1.7.9 and this works as expected.

[~] ruby --version
jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on Java HotSpot(TM) 64-Bit Server VM 1.7.0_45-b18 [darwin-x86_64]
[~] uname -a
Darwin Stefans-MacBook-Pro.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
[~] ruby -e 'p Dir["**/*.o"]'
["objc/osx/bar.o", "objc/osx/bare/foo.o"]

Actually i'm not sure if this was fixed in JRuby, the JVM or is just OS X 10.9 specific behavior.

@enebo enebo modified the milestone: JRuby 9.0.0.0 Jul 14, 2015

@kares kares closed this Nov 14, 2015

@enebo enebo added this to the JRuby 1.7.23 milestone Nov 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.