summaryrefslogtreecommitdiff
path: root/lib/bundler.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler.rb')
-rw-r--r--lib/bundler.rb32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 52bbc57fb5..5da316ec4d 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -191,12 +191,30 @@ module Bundler
end
tmp_home_path.join(login).tap(&:mkpath)
end
- rescue => e
+ rescue RuntimeError => e
raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}")
end
- def user_bundle_path
- Pathname.new(user_home).join(".bundle")
+ def user_bundle_path(dir = "home")
+ env_var, fallback = case dir
+ when "home"
+ ["BUNDLE_USER_HOME", Pathname.new(user_home).join(".bundle")]
+ when "cache"
+ ["BUNDLE_USER_CACHE", user_bundle_path.join("cache")]
+ when "config"
+ ["BUNDLE_USER_CONFIG", user_bundle_path.join("config")]
+ when "plugin"
+ ["BUNDLE_USER_PLUGIN", user_bundle_path.join("plugin")]
+ else
+ raise BundlerError, "Unknown user path requested: #{dir}"
+ end
+ # `fallback` will already be a Pathname, but Pathname.new() is
+ # idempotent so it's OK
+ Pathname.new(ENV.fetch(env_var, fallback))
+ end
+
+ def user_cache
+ user_bundle_path("cache")
end
def home
@@ -211,10 +229,6 @@ module Bundler
bundle_path.join("specifications")
end
- def user_cache
- user_bundle_path.join("cache")
- end
-
def root
@root ||= begin
SharedHelpers.root
@@ -353,7 +367,7 @@ EOF
bin_dir = bin_dir.parent until bin_dir.exist?
# if any directory is not writable, we need sudo
- files = [path, bin_dir] | Dir[path.join("build_info/*").to_s] | Dir[path.join("*").to_s]
+ files = [path, bin_dir] | Dir[bundle_path.join("build_info/*").to_s] | Dir[bundle_path.join("*").to_s]
sudo_needed = files.any? {|f| !File.writable?(f) }
end
@@ -416,7 +430,7 @@ EOF
def load_marshal(data)
Marshal.load(data)
- rescue => e
+ rescue StandardError => e
raise MarshalError, "#{e.class}: #{e.message}"
end