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:
parent
8a144fdedc
commit
785b31bed4
5 changed files with 103 additions and 31 deletions
|
|
@ -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") }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue