Commit 6ca787a
committed
Use realpaths in Cache @path_obj
If file is required from symlinked directory, $LOAD_PATH can have symlinked
path, while subsequent `require`s are resolved to the real path, so we can
end up in situation when we rerequire the same file with different path,
`require` loads the file again and things go BOOM.
```
From: /…/src/bootsnap/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb @ line 18 Kernel#require:
15: def require(path)
16: if resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
17: binding.pry if path == 'set'
=> 18: require_without_cache(resolved)
19: else
20: raise Bootsnap::LoadPathCache::CoreExt.make_load_error(path)
21: end
22: rescue Bootsnap::LoadPathCache::ReturnFalse
23: return false
24: rescue Bootsnap::LoadPathCache::FallbackScan
25: require_without_cache(path)
26: end
[1] pry(main)> path
=> "set"
[2] pry(main)> Set.new.method(:to_s).source_location
=> ["/real_path/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb", 629]
[3] pry(main)> resolved
=> "/symlinked_path/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb"
[4] pry(main)> require_without_cache(resolved)
/symlinked_path/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb:625: warning: already initialized constant Set::InspectKey
/real_path/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb:625: warning: previous definition of InspectKey was here
=> true
[5] pry(main)> Set.new.method(:to_s).source_location
=> ["/symlinked_path/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb", 629]
[6] pry(main)>
```1 parent 09c9235 commit 6ca787a
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
0 commit comments