File.realpath doesn't follow symlinks #538

Closed
ConradIrwin opened this Issue Feb 18, 2013 · 4 comments

Projects

None yet

4 participants

@ConradIrwin
Contributor

I hoped this would just be a case of copying the logic from rubinius, https://github.com/rubinius/rubinius/blob/master/kernel/common/file19.rb#L98, however that code doesn't raise Errno::ENOENT in the case when the symlink is absent or broken rubinius/rubinius#2165. It might be better to copy the code from 1.8.7's Pathname#realpath which has the behaviour I was expecting.

@limhoff-r7

As a work-around I did

file = java.io.File.new(path)
real_path = file.canonical_path
@limhoff-r7 limhoff-r7 added a commit to rapid7/metasploit_data_models that referenced this issue Jun 17, 2014
@limhoff-r7 limhoff-r7 Work-around JRuby Issue 538
[#50752269]

File.realpath does resolve symlinks in JRuby
(jruby/jruby#538).  To work-around the issue,
wrap compatibility code in MetasploitDataModels::File.realpath.
0b4fc03
@LeeXGreen LeeXGreen referenced this issue in whitesmith/rubycritic Feb 4, 2015
Closed

Optionally ignore symlinks with -i #26

@LeeXGreen

This might have been fixed at somepoint between 1.7.9 and 1.7.18:

leeg-mbp-13:~ lee$ ls -l /tmp/
total 16
-rw-r--r--  1 lee   wheel    0 Feb  8 12:36 file.rb
lrwxr-xr-x  1 lee   wheel    7 Feb  8 12:36 link.rb -> file.rb
lrwxr-xr-x  1 lee   wheel    7 Feb  8 12:36 link2.rb -> link.rb

leeg-mbp-13:~ lee$ rvm use 1.7.18
Using /Users/lee/.rvm/gems/jruby-1.7.18

leeg-mbp-13:~ lee$ irb
jruby-1.7.18 :001 > File.realpath('/tmp/link.rb')
 => "/private/tmp/file.rb"
jruby-1.7.18 :002 > File.realpath('/tmp/link2.rb')
 => "/private/tmp/file.rb"
@limhoff-r7

JRuby 1.7.14 fixed the bug.

From: Lee Green
Reply-To: jruby/jruby
Date: Sunday, February 8, 2015 at 1:14 PM
To: jruby/jruby
Cc: Luke Imhoff
Subject: Re: [jruby] File.realpath doesn't follow symlinks (#538)

This might have been fixed at somepoint between 1.7.9 and 1.7.18:

leeg-mbp-13:~ lee$ ls -l /tmp/
total 16
-rw-r--r-- 1 lee wheel 0 Feb 8 12:36 file.rb
lrwxr-xr-x 1 lee wheel 7 Feb 8 12:36 link.rb -> file.rb
lrwxr-xr-x 1 lee wheel 7 Feb 8 12:36 link2.rb -> link.rb

leeg-mbp-13:~ lee$ rvm use 1.7.18
Using /Users/lee/.rvm/gems/jruby-1.7.18

leeg-mbp-13:~ lee$ irb
jruby-1.7.18 :001 > File.realpath('/tmp/link.rb')
=> "/private/tmp/file.rb"
jruby-1.7.18 :002 > File.realpath('/tmp/link2.rb')
=> "/private/tmp/file.rb"


Reply to this email directly or view it on GitHubhttps://github.com/jruby/jruby/issues/538#issuecomment-73426209.

@enebo enebo added this to the JRuby 1.7.14 milestone Feb 9, 2015
@enebo enebo added the core label Feb 9, 2015
@enebo
Member
enebo commented Feb 9, 2015

Based on that snippet I am resolving against 1.7.14. Thanks for the sleuthing!

@enebo enebo closed this Feb 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment