summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-09-06 14:22:29 -0400
committerSamuel Giddins <segiddins@segiddins.me>2016-09-07 14:22:08 +0200
commit02e7f67727b45f59ec0aec4df410e05921d94928 (patch)
tree37f4a195c9b29e9c6bfdd1a1812ca0f3bf9b048b
parent002939bbba581d38ba788016f893a79bca87f855 (diff)
downloadbundler-02e7f67727b45f59ec0aec4df410e05921d94928.tar.gz
Fallback to a temp dir when the home directory is not usable
-rw-r--r--lib/bundler.rb36
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/fetcher/compact_index.rb2
-rw-r--r--lib/bundler/gem_helper.rb2
-rw-r--r--lib/bundler/shared_helpers.rb6
-rw-r--r--lib/bundler/ui/shell.rb4
-rw-r--r--lib/bundler/ui/silent.rb9
7 files changed, 56 insertions, 5 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 8806ae01ef..2be1eee69f 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -143,8 +143,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 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
@@ -403,6 +436,7 @@ EOF
@locked_gems = nil
@bundle_path = nil
@bin_path = nil
+ @user_home = nil
Plugin.reset!
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 8b48be35d2..fdfca7f4b7 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -36,8 +36,10 @@ module Bundler
ensure
self.options ||= {}
Bundler.settings.cli_flags_given = !options.empty?
+ unprinted_warnings = Bundler.ui.unprinted_warnings
Bundler.ui = UI::Shell.new(options)
Bundler.ui.level = "debug" if options["verbose"]
+ unprinted_warnings.each {|w| Bundler.ui.warn(w) }
if ENV["RUBYGEMS_GEMDEPS"] && !ENV["RUBYGEMS_GEMDEPS"].empty?
Bundler.ui.warn(
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index 9461368df5..63b5c8371d 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -61,7 +61,7 @@ module Bundler
compact_index_request :fetch_spec
def available?
- user_home = Pathname.new(Bundler.rubygems.user_home)
+ user_home = Bundler.user_home
return nil unless user_home.directory? && user_home.writable?
# Read info file checksums out of /versions, so we can know if gems are up to date
fetch_uri.scheme != "file" && compact_index_client.update_and_parse_checksums!
diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb
index fdb2db7dbf..73cbf9e0d1 100644
--- a/lib/bundler/gem_helper.rb
+++ b/lib/bundler/gem_helper.rb
@@ -98,7 +98,7 @@ module Bundler
allowed_push_host = @gemspec.metadata["allowed_push_host"]
gem_command += " --host #{allowed_push_host}" if allowed_push_host
end
- unless allowed_push_host || Pathname.new("~/.gem/credentials").expand_path.file?
+ unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file?
raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
end
sh(gem_command)
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index ca4eafd623..6e95793c03 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -39,10 +39,12 @@ module Bundler
bundle_dir = find_directory(".bundle")
return nil unless bundle_dir
- global_bundle_dir = File.join(Bundler.rubygems.user_home, ".bundle")
+ bundle_dir = Pathname.new(bundle_dir)
+
+ global_bundle_dir = Bundler.user_home.join(".bundle")
return nil if bundle_dir == global_bundle_dir
- Pathname.new(bundle_dir)
+ bundle_dir
end
def in_bundle?
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 5c1fa61568..697290f795 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -83,6 +83,10 @@ module Bundler
with_level("silent", &blk)
end
+ def unprinted_warnings
+ []
+ end
+
private
# valimism
diff --git a/lib/bundler/ui/silent.rb b/lib/bundler/ui/silent.rb
index 367eaa58c2..5e0037f488 100644
--- a/lib/bundler/ui/silent.rb
+++ b/lib/bundler/ui/silent.rb
@@ -2,6 +2,10 @@
module Bundler
module UI
class Silent
+ def initialize
+ @warnings = []
+ end
+
def add_color(string, color)
string
end
@@ -13,6 +17,7 @@ module Bundler
end
def warn(message, newline = nil)
+ @warnings |= [message]
end
def error(message, newline = nil)
@@ -44,6 +49,10 @@ module Bundler
def silence
yield
end
+
+ def unprinted_warnings
+ @warnings
+ end
end
end
end