diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-11 05:37:41 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-11 05:37:41 +0000 |
commit | 7434382840c3e8ac9c805d4d09d0a6ed4b4806f8 (patch) | |
tree | 4cf26094005f75cad8632b99283f4617829d23b9 | |
parent | 29b994d2d63150a4195c66b38ce53288ea82078f (diff) | |
download | ruby-7434382840c3e8ac9c805d4d09d0a6ed4b4806f8.tar.gz ruby-7434382840c3e8ac9c805d4d09d0a6ed4b4806f8.tar.xz ruby-7434382840c3e8ac9c805d4d09d0a6ed4b4806f8.zip |
* lib/pathname.rb (realpath_rec): fix handling of symlink to absolute
path.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/pathname.rb | 14 |
2 files changed, 13 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Sat Oct 11 14:35:14 2003 Tanaka Akira <akr@m17n.org> + + * lib/pathname.rb (realpath_rec): fix handling of symlink to absolute + path. + Sat Oct 11 10:19:39 2003 Shugo Maeda <shugo@ruby-lang.org> * lib/monitor.rb: handle exceptions correctly. Thanks, Gennady diff --git a/lib/pathname.rb b/lib/pathname.rb index ff6a1b242..eff3b6cd1 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -111,11 +111,7 @@ class Pathname # it may return relative pathname. # Otherwise it returns absolute pathname. def realpath(force_absolute=true) - if relative? && force_absolute - path = File.join Dir.pwd, @path - else - path = @path - end + path = @path stats = {} if %r{\A/} =~ path || realpath_root?('.', stats) resolved = '/' @@ -123,7 +119,12 @@ class Pathname resolved = '.' end resolved = realpath_rec(resolved, path, stats) - Pathname.new(resolved) + if %r{\A/} !~ resolved && force_absolute + # Note that Dir.pwd and resolved has no symlinks. + Pathname.new(File.join(Dir.pwd, resolved)).cleanpath + else + Pathname.new(resolved) + end end def realpath_root?(path, stats) # :nodoc: @@ -156,6 +157,7 @@ class Pathname if File.lstat(path).symlink? raise Errno::ELOOP.new(path) if rec.include? path link = File.readlink path + resolved = '/' if %r{\A/} =~ link begin rec[path] = true resolved = realpath_rec(resolved, link, stats, rec) |