summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-04-29 14:06:10 +0900
committerHomu <homu@barosl.com>2016-04-29 14:06:10 +0900
commita14a9cf5097c9e7a87309484a0673c78572ab225 (patch)
treeabb1c90831f23131373dff124c59c1864b3c6e83
parent83d7963850cbb1acbcf352767e8f831e442dc788 (diff)
parent5041bc663dec449226f413738b43dbfa913d1b0d (diff)
downloadbundler-a14a9cf5097c9e7a87309484a0673c78572ab225.tar.gz
Auto merge of #4477 - bundler:seg-checksum-mismatch-error, r=indirect
[Updater] Raise a more helpful error on checksum mismatch @indirect this will make diagnosing https://github.com/bundler/bundler/issues/4472 much easier.
-rw-r--r--lib/bundler/fetcher/compact_index.rb3
-rw-r--r--lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb1
-rw-r--r--lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb1
-rw-r--r--lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb22
-rw-r--r--lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb3
-rw-r--r--spec/install/gems/compact_index_spec.rb14
-rw-r--r--spec/support/artifice/compact_index_checksum_mismatch.rb15
7 files changed, 53 insertions, 6 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index c1beee6c75..3d24a9d728 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -61,6 +61,9 @@ module Bundler
def available?
# Read info file checksums out of /versions, so we can know if gems are up to date
fetch_uri.scheme != "file" && compact_index_client.update_and_parse_checksums!
+ rescue CompactIndexClient::Updater::MisMatchedChecksumError => e
+ Bundler.ui.warn(e.message)
+ nil
end
compact_index_request :available?
diff --git a/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb b/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb
index e7d67d9926..1679c17c8a 100644
--- a/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb
+++ b/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require "pathname"
require "set"
diff --git a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb
index 57ef551849..a370fa402d 100644
--- a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb
+++ b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
class Bundler::CompactIndexClient
class Cache
attr_reader :directory
diff --git a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
index a3cdc55140..630318a9be 100644
--- a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
+++ b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb
@@ -1,9 +1,21 @@
+# frozen_string_literal: true
require "stringio"
require "zlib"
class Bundler::CompactIndexClient
class Updater
- class MisMatchedChecksumError < Error; end
+ class MisMatchedChecksumError < Error
+ def initialize(path, server_checksum, local_checksum)
+ @path = path
+ @server_checksum = server_checksum
+ @local_checksum = local_checksum
+ end
+
+ def message
+ "The checksum of /#{@path} does not match the checksum provided by the server! Something is wrong " \
+ "(local checksum is #{@local_checksum.inspect}, was expecting #{@server_checksum.inspect})."
+ end
+ end
def initialize(fetcher)
@fetcher = fetcher
@@ -31,20 +43,20 @@ class Bundler::CompactIndexClient
mode = response.is_a?(Net::HTTPPartialContent) ? "a" : "w"
local_path.open(mode) {|f| f << content }
- return if etag_for(local_path) == response["ETag"]
+ response_etag = response["ETag"]
+ return if etag_for(local_path) == response_etag
if retrying.nil?
local_path.delete
update(local_path, remote_path, :retrying)
else
- raise MisMatchedChecksumError, "Checksum of /#{remote_path} " \
- "does not match the checksum provided by server! Something is wrong."
+ raise MisMatchedChecksumError.new(remote_path, response_etag, etag_for(local_path))
end
end
def etag_for(path)
sum = checksum_for_file(path)
- sum ? '"' << sum << '"' : nil
+ sum ? %("#{sum}") : nil
end
def checksum_for_file(path)
diff --git a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb
index f18c522ae8..64520daead 100644
--- a/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb
+++ b/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
class Bundler::CompactIndexClient
- VERSION = "0.1.0"
+ VERSION = "0.1.0".freeze
end
diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb
index 13645f0ae6..c00e73523b 100644
--- a/spec/install/gems/compact_index_spec.rb
+++ b/spec/install/gems/compact_index_spec.rb
@@ -139,6 +139,20 @@ describe "compact index api" do
should_be_installed "rack 1.0.0"
end
+ it "falls back when the versions endpoint has a checksum mismatch" do
+ gemfile <<-G
+ source "#{source_uri}"
+ gem "rack"
+ G
+
+ bundle! :install, :verbose => true, :artifice => "compact_index_checksum_mismatch"
+ expect(out).to include("Fetching gem metadata from #{source_uri}")
+ expect(out).to include <<-'WARN'
+The checksum of /versions does not match the checksum provided by the server! Something is wrong (local checksum is "\"d41d8cd98f00b204e9800998ecf8427e\"", was expecting "\"123\"").
+ WARN
+ should_be_installed "rack 1.0.0"
+ end
+
it "handles host redirects" do
gemfile <<-G
source "#{source_uri}"
diff --git a/spec/support/artifice/compact_index_checksum_mismatch.rb b/spec/support/artifice/compact_index_checksum_mismatch.rb
new file mode 100644
index 0000000000..4ac328736c
--- /dev/null
+++ b/spec/support/artifice/compact_index_checksum_mismatch.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+require File.expand_path("../compact_index", __FILE__)
+
+Artifice.deactivate
+
+class CompactIndexChecksumMismatch < CompactIndexAPI
+ get "/versions" do
+ headers "ETag" => quote("123")
+ headers "Surrogate-Control" => "max-age=2592000, stale-while-revalidate=60"
+ content_type "text/plain"
+ body ""
+ end
+end
+
+Artifice.activate_with(CompactIndexChecksumMismatch)