Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise when using a bad symlink #28417

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion railties/lib/rails/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ def expanded

# 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
Expand Down
20 changes: 20 additions & 0 deletions railties/test/paths_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,23 @@ def setup
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