summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-02-15 17:46:37 +0000
committerSamuel Giddins <segiddins@segiddins.me>2017-02-22 11:54:11 +1100
commit18eb2e9ae096515f48be199741eb437234f07d05 (patch)
tree0942ea60972807cd9e3d3c71d9071602ddead106
parentef7f81ee5813a0aa1ee651d3c93d746aec06e45a (diff)
downloadbundler-18eb2e9ae096515f48be199741eb437234f07d05.tar.gz
Auto merge of #5421 - bundler:seg-read-only-fs-no-global-settings, r=indirect
Don't read global settings on a read-only FS with no $HOME Closes https://github.com/bundler/bundler/issues/5371 This is an alternative to https://github.com/bundler/bundler/pull/5385 (cherry picked from commit 42b1e1b9c3f4b3a45cd27214ef656911951b4d94)
-rw-r--r--lib/bundler.rb2
-rw-r--r--lib/bundler/settings.rb6
-rw-r--r--spec/bundler/settings_spec.rb13
-rw-r--r--spec/support/helpers.rb2
-rw-r--r--spec/support/path.rb4
-rw-r--r--spec/support/rubygems_ext.rb1
6 files changed, 25 insertions, 3 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 0aa9082352..411b85296f 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -284,7 +284,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 04e221a57c..32e1fb7626 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 }
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 815671bba5..8095331b0a 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -10,8 +10,8 @@ module Spec
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