From ad44d7a054f3897154d5c275ddecade4032d0d54 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 14 Mar 2017 17:16:32 -0500 Subject: Raise when using a bad symlink There was a case where a dev made a symlink that worked on some machines and not on others. The issue manifested itself on a machine with `RAILS_ENV=staging` as the had their `config/environments/staging.rb` symlinked to another config file. The behavior was very hard to track down. Current behavior: If you use a bad symlink in a file, you get no warnings or failures or anything. If you have a bad symlink it just ignores the file as if it didn't exist (`File.exist?` returns false for a bad symlink). Patch behavior: With this patch when a file is not present we check if a symlink exists. If it does, that indicates there is a bad symlink and we should raise ``` File "config/environments/staging.rb" is a symlink that does not point to a valid file ``` --- railties/lib/rails/paths.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/paths.rb') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index af3be10a31..6bdb673215 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -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 -- cgit v1.2.3