* lib/pathname.rb (realpath_rec): fix handling of symlink to absolute
path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
764722dc27
commit
6fc32eb8bb
@ -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>
|
Sat Oct 11 10:19:39 2003 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/monitor.rb: handle exceptions correctly. Thanks, Gennady
|
* lib/monitor.rb: handle exceptions correctly. Thanks, Gennady
|
||||||
|
@ -111,11 +111,7 @@ class Pathname
|
|||||||
# it may return relative pathname.
|
# it may return relative pathname.
|
||||||
# Otherwise it returns absolute pathname.
|
# Otherwise it returns absolute pathname.
|
||||||
def realpath(force_absolute=true)
|
def realpath(force_absolute=true)
|
||||||
if relative? && force_absolute
|
|
||||||
path = File.join Dir.pwd, @path
|
|
||||||
else
|
|
||||||
path = @path
|
path = @path
|
||||||
end
|
|
||||||
stats = {}
|
stats = {}
|
||||||
if %r{\A/} =~ path || realpath_root?('.', stats)
|
if %r{\A/} =~ path || realpath_root?('.', stats)
|
||||||
resolved = '/'
|
resolved = '/'
|
||||||
@ -123,8 +119,13 @@ class Pathname
|
|||||||
resolved = '.'
|
resolved = '.'
|
||||||
end
|
end
|
||||||
resolved = realpath_rec(resolved, path, stats)
|
resolved = realpath_rec(resolved, path, stats)
|
||||||
|
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)
|
Pathname.new(resolved)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def realpath_root?(path, stats) # :nodoc:
|
def realpath_root?(path, stats) # :nodoc:
|
||||||
path_stat = stats[path] ||= File.lstat(path)
|
path_stat = stats[path] ||= File.lstat(path)
|
||||||
@ -156,6 +157,7 @@ class Pathname
|
|||||||
if File.lstat(path).symlink?
|
if File.lstat(path).symlink?
|
||||||
raise Errno::ELOOP.new(path) if rec.include? path
|
raise Errno::ELOOP.new(path) if rec.include? path
|
||||||
link = File.readlink path
|
link = File.readlink path
|
||||||
|
resolved = '/' if %r{\A/} =~ link
|
||||||
begin
|
begin
|
||||||
rec[path] = true
|
rec[path] = true
|
||||||
resolved = realpath_rec(resolved, link, stats, rec)
|
resolved = realpath_rec(resolved, link, stats, rec)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user