From ef559704bb4a2b9163a5be8616634e3aea830a16 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 10 Feb 2017 09:46:47 -0800 Subject: In specs, set TMPDIR to be ./tmp/tmpdir This was, modifications to the temporary directory are blown away between each test and don't clutter the user's FS --- spec/support/helpers.rb | 4 ++-- spec/support/path.rb | 4 ++++ spec/support/rubygems_ext.rb | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 738b1f7b3b..5e66713e5a 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -3,15 +3,15 @@ module Spec module Helpers def reset! Dir["#{tmp}/{gems/*,*}"].each do |dir| - next if %(base remote1 gems rubygems).include?(File.basename(dir)) + next if %w(base remote1 gems rubygems).include?(File.basename(dir)) if ENV["BUNDLER_SUDO_TESTS"] `sudo rm -rf #{dir}` else FileUtils.rm_rf(dir) end end - FileUtils.mkdir_p(tmp) FileUtils.mkdir_p(home) + FileUtils.mkdir_p(tmpdir) ENV["BUNDLE_TRAMPOLINE_DISABLE"] = "1" Bundler.reset! Bundler.ui = nil diff --git a/spec/support/path.rb b/spec/support/path.rb index cf77adb509..2b929003fb 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -89,6 +89,10 @@ module Spec bundled_app ".bundle", "plugin", "gems", *args end + def tmpdir(*args) + tmp "tmpdir", *args + end + extend self end end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index b75350f473..88886c3f1f 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -42,6 +42,7 @@ module Spec end ENV["HOME"] = Path.home.to_s + ENV["TMPDIR"] = Path.tmpdir.to_s Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end -- cgit v1.2.1 From 8cf7d8c488cc24334a0022cfc9b89fe95659ec52 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 10 Feb 2017 09:57:59 -0800 Subject: [Settings] Allow not reading the global config file when there is no $HOME and $TMPDIR is not writable --- lib/bundler.rb | 2 +- lib/bundler/settings.rb | 6 +++++- spec/bundler/settings_spec.rb | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index c98dece747..914bdb3762 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -176,7 +176,7 @@ module Bundler tmp_home_path.join(login).tap(&:mkpath) end rescue => e - raise "#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}" + raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}") end def user_bundle_path diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index e98940721e..7339f721ad 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -285,7 +285,11 @@ module Bundler if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty? Pathname.new(ENV["BUNDLE_CONFIG"]) else - Bundler.user_bundle_path.join("config") + begin + Bundler.user_bundle_path.join("config") + rescue PermissionError, GenericSystemCallError + nil + end end end diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index c67ae81bac..020897882c 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -62,6 +62,19 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow end end + describe "#global_config_file" do + context "when $HOME is not accessible" do + context "when $TMPDIR is not writable" do + it "does not raise" do + expect(Bundler.rubygems).to receive(:user_home).twice.and_return(nil) + expect(FileUtils).to receive(:mkpath).twice.with(File.join(Dir.tmpdir, "bundler", "home")).and_raise(Errno::EROFS, "Read-only file system @ dir_s_mkdir - /tmp/bundler") + + expect(subject.send(:global_config_file)).to be_nil + end + end + end + end + describe "#[]" do context "when the local config file is not found" do subject(:settings) { described_class.new } -- cgit v1.2.1