diff options
author | The Bundler Bot <bot@bundler.io> | 2018-07-10 06:23:41 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2018-07-10 06:23:41 +0000 |
commit | 9ca3afe30272a1403782cce0d600e7411e6cf709 (patch) | |
tree | 51b0cdb5c9b3fe1b53cf96ada4c1c7b8ef4e45e9 /lib | |
parent | 7f0b57fa54aa946ad2fbcc122dcc41ab45287acd (diff) | |
parent | 865ec52ae87c29473405ce587977dd3eaef453ae (diff) | |
download | bundler-9ca3afe30272a1403782cce0d600e7411e6cf709.tar.gz |
Auto merge of #6502 - ojab:1-16-stable, r=indirect
Use realpath in clean_load_path
see #6465, basically we're not rejecting `bundler_lib` because we have symlink there and real path in `$LOAD_PATH`
```
$ irb
2.5.1 :001 > require 'bundler/setup'
# what happens next will shock you
From: /real_path/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.2/lib/bundler/shared_helpers.rb @ line 339 Bundler::SharedHelpers#clean_load_path:
330: def clean_load_path
331: # handle 1.9 where system gems are always on the load path
332: return unless defined?(::Gem)
333:
334: bundler_lib = bundler_ruby_lib
335:
336: loaded_gem_paths = Bundler.rubygems.loaded_gem_paths
337:
338: binding.pry
=> 339: $LOAD_PATH.reject! do |p|
340: path = File.expand_path(p)
341: path = File.realpath(path) if File.exist?(path)
342: next if path.start_with?(bundler_lib)
343: loaded_gem_paths.delete(p)
344: end
345: $LOAD_PATH.uniq!
346: end
[1] pry(#<Bundler::Runtime>)> bundler_lib
=> "/real_path/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.2/lib"
[2] pry(#<Bundler::Runtime>)> loaded_gem_paths
=> ["/symlinked_path/.rvm/gems/ruby-2.5.1@global/gems/did_you_mean-1.2.0/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.2/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/byebug-10.0.2/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/extensions/x86_64-linux/2.5.0/byebug-10.0.2",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/coderay-1.1.2/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/method_source-0.9.0/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/pry-0.11.3/lib",
"/symlinked_path/.rvm/gems/ruby-2.5.1/gems/pry-byebug-3.6.0/lib",
"/real_path/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/fileutils-1.0.2/lib",
"/real_path/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/psych-3.0.2/lib",
"/real_path/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0/psych-3.0.2"]
```
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/shared_helpers.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 93e2a35b54..b85e58ac66 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -331,7 +331,7 @@ module Bundler end def bundler_ruby_lib - File.expand_path("../..", __FILE__) + resolve_path File.expand_path("../..", __FILE__) end def clean_load_path @@ -343,12 +343,23 @@ module Bundler loaded_gem_paths = Bundler.rubygems.loaded_gem_paths $LOAD_PATH.reject! do |p| - next if File.expand_path(p).start_with?(bundler_lib) + next if resolve_path(p).start_with?(bundler_lib) loaded_gem_paths.delete(p) end $LOAD_PATH.uniq! end + def resolve_path(path) + expanded = File.expand_path(path) + return expanded unless File.respond_to?(:realpath) + + while File.exist?(expanded) && File.realpath(expanded) != expanded + expanded = File.realpath(expanded) + end + + expanded + end + def prints_major_deprecations? require "bundler" deprecation_release = Bundler::VERSION.split(".").drop(1).include?("99") |