Skip to content

Commit

Permalink
Cleanup after geminstalls that don't finish because of errors. Closes r…
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlhuda committed Dec 9, 2009
1 parent 327af9c commit 3f926f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
11 changes: 9 additions & 2 deletions lib/bundler/repository.rb
Expand Up @@ -160,6 +160,9 @@ def expand_gemfile(spec, options)
:bin_dir => @bindir
))
installer.install
rescue Gem::InstallError
cleanup_spec(spec)
raise
ensure
Gem::Command.build_args = []
end
Expand Down Expand Up @@ -189,8 +192,7 @@ def cleanup(valid, options)

to_delete.each do |spec|
Bundler.logger.info "Deleting gem: #{spec.name} (#{spec.version})"
FileUtils.rm_rf(@path.join("specifications", "#{spec.full_name}.gemspec"))
FileUtils.rm_rf(@path.join("gems", spec.full_name))
cleanup_spec(spec)
# Cleanup the bin directory
spec.executables.each do |bin|
next if valid_executables.include?(bin)
Expand All @@ -200,6 +202,11 @@ def cleanup(valid, options)
end
end

def cleanup_spec(spec)
FileUtils.rm_rf(@path.join("specifications", "#{spec.full_name}.gemspec"))
FileUtils.rm_rf(@path.join("gems", spec.full_name))
end

def expand(options)
each_repo do |repo|
repo.expand(options)
Expand Down
27 changes: 20 additions & 7 deletions spec/bundler/cli_spec.rb
Expand Up @@ -9,6 +9,13 @@
source "file://#{gem_repo1}"
gem "very_simple_binary"
Gemfile

File.open("#{bundled_app}/build.yml", "w+") do |file|
file.puts <<-build_options.gsub(/^ /, '')
very_simple_binary:
simple: wot
build_options
end
end

it "fails if the option is not provided" do
Expand All @@ -20,13 +27,6 @@
end

it "passes if a yaml is specified that contains the necessary options" do
File.open("#{bundled_app}/build.yml", "w+") do |file|
file.puts <<-build_options.gsub(/^ /, '')
very_simple_binary:
simple: wot
build_options
end

Dir.chdir(bundled_app) do
@output = gem_command :bundle, "--build-options=build.yml 2>&1"
end
Expand All @@ -40,6 +40,19 @@

out.should == "VerySimpleBinaryInC"
end

it "does not skip the binary gem if compiling failed in a previous bundle" do
Dir.chdir(bundled_app)

gem_command :bundle, "--backtrace 2>&1" # will fail
gem_command :bundle, "--build-options=build.yml 2>&1"

out = run_in_context <<-RUBY
require "very_simple_binary"
puts VerySimpleBinaryInC
RUBY
out.should == "VerySimpleBinaryInC"
end
end

describe "it working" do
Expand Down

0 comments on commit 3f926f0

Please sign in to comment.