diff options
author | Andre Arko <andre@arko.net> | 2015-05-04 22:28:12 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2015-05-04 22:33:06 -0700 |
commit | ae865a073c4e713d6f9c2a6143a0e81041031eb8 (patch) | |
tree | 0d678d4914cb5ceface9d3f7f48d89af4c7ebe8e | |
parent | 8050cd6a41d94851a6a6fad2fdb29b9b534bc74c (diff) | |
download | bundler-ae865a073c4e713d6f9c2a6143a0e81041031eb8.tar.gz |
clean up tmp dirs if they get created
-rw-r--r-- | lib/bundler.rb | 8 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/path/installer.rb | 19 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 8 |
4 files changed, 18 insertions, 19 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 49d9fd6883..197e88c222 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -206,13 +206,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 defined?(@tmp) && @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 50133d2978..cf30589673 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/source/path/installer.rb b/lib/bundler/source/path/installer.rb index a3e71e37a4..ef9faa9cbe 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 = true @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 cba3763b47..797988f365 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -160,9 +160,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) @@ -392,10 +390,12 @@ module Bundler if Bundler.requires_sudo? Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/cache" - Bundler.sudo "mv #{Bundler.tmp(spec.full_name)}/cache/#{spec.full_name}.gem #{gem_path}" + Bundler.sudo "mv #{download_path}/cache/#{spec.full_name}.gem #{gem_path}" end gem_path + ensure + Bundler.rm_rf(download_path) if Bundler.requires_sudo? end def builtin_gem?(spec) |