From ea31c5bcd1bc1a019a6aee2b3f3b16813d7ff96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 27 May 2022 20:46:42 +0200 Subject: [rubygems/rubygems] Fix crash when installing gems with symlinks If BUNDLE_PATH is configured to a symlinked path, installing gems with symlinks would crash with an error like this: ``` Gem::Package::SymlinkError: installing symlink 'man/man0/README.markdown' pointing to parent path /usr/home/stevewi/srv/mail/lib/tools/.vendor/ruby/3.1.0/gems/binman-5.1.0/README.markdown of /srv/mail/lib/tools/.vendor/ruby/3.1.0/gems/binman-5.1.0 is not allowed ``` This commit fixes the problem by changing the bundle path to be the realpath of the configured value, right after we're sure the path has been created. https://github.com/rubygems/rubygems/commit/3cd3dd142a --- lib/bundler.rb | 11 +++++++++++ lib/bundler/inline.rb | 1 + lib/bundler/installer.rb | 11 +---------- lib/bundler/source/rubygems.rb | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/bundler.rb b/lib/bundler.rb index 0be01d1808..c99114ae64 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -97,6 +97,17 @@ module Bundler @bundle_path ||= Pathname.new(configured_bundle_path.path).expand_path(root) end + def create_bundle_path + SharedHelpers.filesystem_access(bundle_path.to_s) do |p| + mkdir_p(p) + end unless bundle_path.exist? + + @bundle_path = bundle_path.realpath + rescue Errno::EEXIST + raise PathError, "Could not install to path `#{bundle_path}` " \ + "because a file already exists at that path. Either remove or rename the file so the directory can be created." + end + def configured_bundle_path @configured_bundle_path ||= settings.path.tap(&:validate!) end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index db1ca2de65..8ef580f1f0 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -38,6 +38,7 @@ def gemfile(install = false, options = {}, &gemfile) raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty? begin + Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir)) old_gemfile = ENV["BUNDLE_GEMFILE"] Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile" diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 915a04c0dc..f195d36600 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -66,7 +66,7 @@ module Bundler # require paths and save them in a `setup.rb` file. See `bundle standalone --help` for more # information. def run(options) - create_bundle_path + Bundler.create_bundle_path ProcessLock.lock do if Bundler.frozen_bundle? @@ -262,15 +262,6 @@ module Bundler end end - def create_bundle_path - SharedHelpers.filesystem_access(Bundler.bundle_path.to_s) do |p| - Bundler.mkdir_p(p) - end unless Bundler.bundle_path.exist? - rescue Errno::EEXIST - raise PathError, "Could not install to path `#{Bundler.bundle_path}` " \ - "because a file already exists at that path. Either remove or rename the file so the directory can be created." - end - # returns whether or not a re-resolve was needed def resolve_if_needed(options) if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file? diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index b37bfbccb9..5dceacbae4 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -499,7 +499,7 @@ module Bundler end def rubygems_dir - Bundler.rubygems.gem_dir + Bundler.bundle_path end def default_cache_path_for(dir) -- cgit v1.2.3