summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2015-05-05 14:50:58 -0700
committerAndre Arko <andre@arko.net>2015-05-07 08:40:33 +0100
commit4820162414b6d7ed1eee5d8c8397533cadff46e3 (patch)
treee23724a5574e5cb5baf39aceadd592ae8940d320
parent1d9f3763aabc842d50cc2a88c77b216c5be77c64 (diff)
downloadbundler-4820162414b6d7ed1eee5d8c8397533cadff46e3.tar.gz
clean up tmp dirs if they get created
backport of ae865a073c4e713d6f9c2a6143a0e81041031eb8
-rw-r--r--lib/bundler.rb8
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/fetcher.rb2
-rw-r--r--lib/bundler/source/path/installer.rb19
-rw-r--r--lib/bundler/source/rubygems.rb4
5 files changed, 17 insertions, 18 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 38a3de0f38..22a35aa9bd 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -212,13 +212,11 @@ module Bundler
end
def tmp(name = Process.pid.to_s)
- @tmp ||= Pathname.new Dir.mktmpdir("bundler")
- @tmp.join(name)
+ Pathname.new(Dir.mktmpdir(["bundler", name]))
end
- def cleanup
- FileUtils.remove_entry_secure(@tmp) if @tmp
- rescue
+ def rm_rf(path)
+ FileUtils.remove_entry_secure(path) if path && File.exist?(path)
end
def settings
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 6a22072565..ac193d72c8 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -11,8 +11,6 @@ module Bundler
rescue Exception => e
Bundler.ui = UI::Shell.new
raise e
- ensure
- Bundler.cleanup
end
def initialize(*args)
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index 46ac8e44e8..19225658f0 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -68,6 +68,8 @@ module Bundler
end
gem_path
+ ensure
+ Bundler.rm_rf(download_path) if Bundler.requires_sudo?
end
def user_agent
diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb
index 6f264489fb..3b368816c0 100644
--- a/lib/bundler/source/path/installer.rb
+++ b/lib/bundler/source/path/installer.rb
@@ -7,31 +7,34 @@ module Bundler
def initialize(spec, options = {})
@spec = spec
- @tmp_bin_dir = "#{Bundler.tmp(spec.full_name)}/bin"
- @gem_bin_dir = "#{Bundler.rubygems.gem_dir}/bin"
- @bin_dir = Bundler.requires_sudo? ? @tmp_bin_dir : @gem_bin_dir
@gem_dir = Bundler.rubygems.path(spec.full_gem_path)
@wrappers = options[:wrappers] || true
@env_shebang = options[:env_shebang] || true
@format_executable = options[:format_executable] || false
@build_args = options[:build_args] || Bundler.rubygems.build_args
+ @gem_bin_dir = "#{Bundler.rubygems.gem_dir}/bin"
+
+ if Bundler.requires_sudo?
+ @tmp_dir = Bundler.tmp(spec.full_name).to_s
+ @bin_dir = "#{@tmp_dir}/bin"
+ else
+ @bin_dir = @gem_bin_dir
+ end
end
def generate_bin
return if spec.executables.nil? || spec.executables.empty?
- if Bundler.requires_sudo?
- FileUtils.mkdir_p(@tmp_bin_dir) unless File.exist?(@tmp_bin_dir)
- end
-
super
if Bundler.requires_sudo?
Bundler.mkdir_p @gem_bin_dir
spec.executables.each do |exe|
- Bundler.sudo "cp -R #{@tmp_bin_dir}/#{exe} #{@gem_bin_dir}"
+ Bundler.sudo "cp -R #{@bin_dir}/#{exe} #{@gem_bin_dir}"
end
end
+ ensure
+ Bundler.rm_rf(@tmp_dir) if Bundler.requires_sudo?
end
end
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 925bec6662..0112e2be15 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -145,9 +145,7 @@ module Bundler
spec.loaded_from = loaded_from(spec)
["Installing #{version_message(spec)}", spec.post_install_message]
ensure
- if install_path && Bundler.requires_sudo?
- FileUtils.remove_entry_secure(install_path)
- end
+ Bundler.rm_rf(install_path) if Bundler.requires_sudo?
end
def cache(spec, custom_path = nil)