diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-09-06 16:31:25 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-09-06 16:31:25 -0500 |
commit | f42027808b304fd6c2ac2a71453278b8c81cb390 (patch) | |
tree | dc2b78b1eb7108af59eff19aeebef8eadd502995 | |
parent | dbb0aede6f16e1a252f9a49b48673bfc30bd1242 (diff) | |
download | bundler-seg-remove-failed-gem-download.tar.gz |
[Source::Rubygems] Remove .gem if downloaded package is invalidseg-remove-failed-gem-download
-rw-r--r-- | lib/bundler/source/rubygems.rb | 10 | ||||
-rw-r--r-- | spec/install/failure_spec.rb | 19 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index fa60bb0c84..e083953d42 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -120,8 +120,14 @@ module Bundler uris.uniq! Installer.ambiguous_gems << [spec.name, *uris] if uris.length > 1 - s = Bundler.rubygems.spec_from_gem(fetch_gem(spec), Bundler.settings["trust-policy"]) - spec.__swap__(s) + path = fetch_gem(spec) + begin + s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"]) + spec.__swap__(s) + rescue + Bundler.rm_rf(path) + raise + end end unless Bundler.settings[:no_install] diff --git a/spec/install/failure_spec.rb b/spec/install/failure_spec.rb index 896138c659..44006be52e 100644 --- a/spec/install/failure_spec.rb +++ b/spec/install/failure_spec.rb @@ -28,5 +28,24 @@ In Gemfile: activesupport M end + + context "because the downloaded .gem was invalid" do + before do + build_repo4 do + build_gem "a" + end + + gem_repo4("gems", "a-1.0.gem").open("w") {|f| f << "<html></html>" } + end + + it "removes the downloaded .gem" do + install_gemfile <<-G + source "file:#{gem_repo4}" + gem "a" + G + + expect(default_bundle_path("cache", "a-1.0.gem")).not_to exist + end + end end end |