1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* file.c: add optional basedir argument for realpath/realdirpath.

(realpath_internal): handle basedir.
  (rb_file_s_realpath): extract basedir from argument list.
  (rb_file_s_realdirpath): extract basedir from argument list.

* lib/pathname.rb (realpath): pass basedir.
  (realdirpath): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2010-03-07 04:55:34 +00:00
parent 8a144fdedc
commit 785b31bed4
5 changed files with 103 additions and 31 deletions

View file

@ -288,8 +288,8 @@ class TestPathname < Test::Unit::TestCase
return true
end
def realpath(path)
Pathname.new(path).realpath.to_s
def realpath(path, basedir=nil)
Pathname.new(path).realpath(basedir).to_s
end
def test_realpath
@ -301,6 +301,7 @@ class TestPathname < Test::Unit::TestCase
File.symlink("loop", "#{dir}/loop")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop", dir) }
File.symlink("../#{File.basename(dir)}/./not-exist-target", "#{dir}/not-exist2")
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist2") }
@ -314,6 +315,7 @@ class TestPathname < Test::Unit::TestCase
Dir.mkdir("exist")
assert_equal("#{dir}/exist", realpath("exist"))
assert_raise(Errno::ELOOP) { realpath("../loop", "#{dir}/exist") }
File.symlink("loop1/loop1", "loop1")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop1") }