summaryrefslogtreecommitdiff
path: root/lib/bundler.rb
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-09-30 17:11:17 +0900
committerHomu <homu@barosl.com>2016-09-30 17:11:17 +0900
commitc8991533ff4a6c512e9b18e037c2da581c6d76fb (patch)
tree0704426a5375abcc38125c3b673160874a159a4e /lib/bundler.rb
parentdd6aef97a5f2e7173f406267256a8c319d6134ab (diff)
parent2ac0c510a4528d3eeef7fcc1b8e68bb7e053ebac (diff)
downloadbundler-c8991533ff4a6c512e9b18e037c2da581c6d76fb.tar.gz
Auto merge of #4951 - bundler:seg-no-writable-home, r=indirect
Fallback to a temp dir when the home directory is not usable Closes https://github.com/bundler/bundler/issues/4778 This is an alternative to https://github.com/bundler/bundler/pull/4886 \c @allenzhao @indirect
Diffstat (limited to 'lib/bundler.rb')
-rw-r--r--lib/bundler.rb38
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 249c4e2dc6..f25d43e001 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -3,6 +3,8 @@ require "fileutils"
require "pathname"
require "rbconfig"
require "thread"
+require "tmpdir"
+
require "bundler/errors"
require "bundler/environment_preserver"
require "bundler/gem_remote_fetcher"
@@ -143,8 +145,41 @@ module Bundler
"#{Bundler.rubygems.ruby_engine}/#{Bundler.rubygems.config_map[:ruby_version]}"
end
+ def user_home
+ @user_home ||= begin
+ home = Bundler.rubygems.user_home
+ warning = "Your home directory is not set properly:"
+ if home.nil?
+ warning += "\n * It is not set at all"
+ elsif !File.directory?(home)
+ warning += "\n * `#{home}` is not a directory"
+ elsif !File.writable?(home)
+ warning += "\n * `#{home}` is not writable"
+ else
+ return @user_home = Pathname.new(home)
+ end
+
+ login = Etc.getlogin || "unknown"
+
+ tmp_home = Pathname.new(Dir.tmpdir).join("bundler", "home", login)
+ begin
+ SharedHelpers.filesystem_access(tmp_home, :write) do |p|
+ FileUtils.mkdir_p(p)
+ end
+ rescue => e
+ warning += "\n\nBundler also failed to create a temporary home directory at `#{tmp_home}`:\n#{e}"
+ raise warning
+ end
+
+ warning += "\n\nBundler will use `#{tmp_home}` as your home directory temporarily"
+
+ Bundler.ui.warn(warning)
+ tmp_home
+ end
+ end
+
def user_bundle_path
- Pathname.new(Bundler.rubygems.user_home).join(".bundle")
+ Pathname.new(user_home).join(".bundle")
end
def home
@@ -409,6 +444,7 @@ EOF
@locked_gems = nil
@bundle_path = nil
@bin_path = nil
+ @user_home = nil
Plugin.reset!