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

Merge pull request #28417 from schneems/schneems/symlink-failures

Raise when using a bad symlink
This commit is contained in:
Andrew White 2017-03-30 06:26:25 +01:00 committed by GitHub
commit 51aa5b04c6
2 changed files with 28 additions and 1 deletions

View file

@ -205,7 +205,14 @@ module Rails
# Returns all expanded paths but only if they exist in the filesystem.
def existent
expanded.select { |f| File.exist?(f) }
expanded.select do |f|
does_exist = File.exist?(f)
if !does_exist && File.symlink?(f)
raise "File #{f.inspect} is a symlink that does not point to a valid file"
end
does_exist
end
end
def existent_directories

View file

@ -274,3 +274,23 @@ class PathsTest < ActiveSupport::TestCase
end
end
end
class PathsIntegrationTest < ActiveSupport::TestCase
test "A failed symlink is still a valid file" do
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
FileUtils.mkdir_p("foo")
File.symlink("foo/doesnotexist.rb", "foo/bar.rb")
assert_equal true, File.symlink?("foo/bar.rb")
root = Rails::Paths::Root.new("foo")
root.add "bar.rb"
exception = assert_raises(RuntimeError) do
root["bar.rb"].existent
end
assert_match File.expand_path("foo/bar.rb"), exception.message
end
end
end
end