FileUtils.ln_s should raise an error if symlinking to a subpath
which does not exist (and :force => true is not provided)
This commit is contained in:
parent
6a2a821c8a
commit
973a2ae1f3
@ -61,6 +61,10 @@ module FakeFS
|
||||
glob(pattern)
|
||||
end
|
||||
|
||||
def self.exists?(path)
|
||||
File.exists?(path) && File.directory?(path)
|
||||
end
|
||||
|
||||
def self.chdir(dir, &blk)
|
||||
FileSystem.chdir(dir, &blk)
|
||||
end
|
||||
|
@ -40,9 +40,17 @@ module FakeFS
|
||||
|
||||
def ln_s(target, path, options = {})
|
||||
options = { :force => false }.merge(options)
|
||||
(FileSystem.find(path) and !options[:force]) ? raise(Errno::EEXIST, path) : FileSystem.delete(path)
|
||||
(FileSystem.find(path) && !options[:force]) ?
|
||||
raise(Errno::EEXIST, path) :
|
||||
FileSystem.delete(path)
|
||||
|
||||
if !options[:force] && !Dir.exists?(File.dirname(path))
|
||||
raise Errno::ENOENT, path
|
||||
end
|
||||
|
||||
FileSystem.add(path, FakeSymlink.new(target))
|
||||
end
|
||||
|
||||
def ln_sf(target, path)
|
||||
ln_s(target, path, { :force => true })
|
||||
end
|
||||
|
@ -142,18 +142,33 @@ class FakeFSTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_symlinks_in_different_directories
|
||||
FileUtils.mkdir_p("/path/to/bar")
|
||||
FileUtils.mkdir_p(target = "/path/to/foo/target")
|
||||
|
||||
FileUtils.ln_s(target, link = "/path/to/bar/symlink")
|
||||
assert_equal target, File.readlink(link)
|
||||
end
|
||||
|
||||
def test_symlinks_to_symlinks
|
||||
FileUtils.mkdir_p(target = "/path/to/foo/target")
|
||||
FileUtils.mkdir_p("/path/to/bar")
|
||||
FileUtils.mkdir_p("/path/to/bar2")
|
||||
|
||||
FileUtils.ln_s(target, link1 = "/path/to/bar/symlink")
|
||||
FileUtils.ln_s(link1, link2 = "/path/to/bar2/symlink")
|
||||
assert_equal link1, File.readlink(link2)
|
||||
end
|
||||
|
||||
def test_symlink_to_symlinks_should_raise_error_if_dir_doesnt_exist
|
||||
FileUtils.mkdir_p(target = "/path/to/foo/target")
|
||||
|
||||
assert !Dir.exists?("/path/to/bar")
|
||||
|
||||
assert_raise Errno::ENOENT do
|
||||
FileUtils.ln_s(target, "/path/to/bar/symlink")
|
||||
end
|
||||
end
|
||||
|
||||
def test_knows_symlinks_are_symlinks
|
||||
FileUtils.mkdir_p(target = "/path/to/target")
|
||||
FileUtils.ln_s(target, link = "/path/to/symlink")
|
||||
|
Loading…
Reference in New Issue
Block a user