From 1e1947df28f94b9c99f09ee4ec3e83eba557d8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 26 Oct 2020 18:13:53 +0100 Subject: [PATCH] Add missing `fileutils` require in rubygems installer Bundler inherits from rubygems installer and uses this method directly. It can happen that `fileutils` is not yet required at that point. To repro the issue I needed to make sure that the executables inside dummy specs have the executable bit set. Otherwise a different code path that _does_ require `fileutils` is run. This seems like a good thing anyways since it better resembles the real world. --- bundler/spec/install/gemfile/git_spec.rb | 6 +++++- bundler/spec/support/builders.rb | 1 + lib/rubygems/installer.rb | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bundler/spec/install/gemfile/git_spec.rb b/bundler/spec/install/gemfile/git_spec.rb index a70fb18c45c6..edb19b1827cd 100644 --- a/bundler/spec/install/gemfile/git_spec.rb +++ b/bundler/spec/install/gemfile/git_spec.rb @@ -30,11 +30,15 @@ expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"]).to have_attributes :size => 1 end - it "caches the git repo globally" do + it "caches the git repo globally and properly uses the cached repo on the next invocation" do simulate_new_machine bundle "config set global_gem_cache true" bundle :install expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes :size => 1 + + bundle "install --verbose" + expect(err).to be_empty + expect(out).to include("Using foo 1.0 from #{lib_path("foo")}") end it "caches the evaluated gemspec" do diff --git a/bundler/spec/support/builders.rb b/bundler/spec/support/builders.rb index dca784f1b091..02a2c0f65990 100644 --- a/bundler/spec/support/builders.rb +++ b/bundler/spec/support/builders.rb @@ -523,6 +523,7 @@ def @spec.validate(*); end file = Pathname.new(path).join(file) FileUtils.mkdir_p(file.dirname) File.open(file, "w") {|f| f.puts source } + File.chmod("+x", file) if @spec.executables.map {|exe| "#{@spec.bindir}/#{exe}" }.include?(file) end path end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 0c054562a926..2c583743b9b0 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -530,6 +530,7 @@ def generate_plugins # :nodoc: def generate_bin_script(filename, bindir) bin_script_path = File.join bindir, formatted_program_filename(filename) + require 'fileutils' FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers File.open bin_script_path, 'wb', 0755 do |file|