diff options
author | schneems <richard.schneeman@gmail.com> | 2017-03-14 17:16:32 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2017-03-14 17:23:17 -0500 |
commit | ad44d7a054f3897154d5c275ddecade4032d0d54 (patch) | |
tree | 2ad99a5a7c5edbe79a36c815653c34a9e4edf075 /railties/lib/rails/paths.rb | |
parent | 410f876dad26273f7008e0123830aae6b075529e (diff) | |
download | rails-ad44d7a054f3897154d5c275ddecade4032d0d54.tar.gz rails-ad44d7a054f3897154d5c275ddecade4032d0d54.tar.bz2 rails-ad44d7a054f3897154d5c275ddecade4032d0d54.zip |
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
```
Diffstat (limited to 'railties/lib/rails/paths.rb')
-rw-r--r-- | railties/lib/rails/paths.rb | 9 |
1 files changed, 8 insertions, 1 deletions
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 |