diff --git a/bundler/lib/bundler/compact_index_client/updater.rb b/bundler/lib/bundler/compact_index_client/updater.rb index 40232019bca6..24266f2fe65d 100644 --- a/bundler/lib/bundler/compact_index_client/updater.rb +++ b/bundler/lib/bundler/compact_index_client/updater.rb @@ -66,8 +66,8 @@ def update(local_path, remote_path, retrying = nil) end end - response_etag = (response["ETag"] || "").gsub(%r{\AW/}, "") - if etag_for(local_temp_path) == response_etag + etag = (response["ETag"] || "").gsub(%r{\AW/}, "") + if etag.length.zero? || etag_for(local_temp_path) == etag SharedHelpers.filesystem_access(local_path) do FileUtils.mv(local_temp_path, local_path) end @@ -75,7 +75,7 @@ def update(local_path, remote_path, retrying = nil) end if retrying - raise MisMatchedChecksumError.new(remote_path, response_etag, etag_for(local_temp_path)) + raise MisMatchedChecksumError.new(remote_path, etag, etag_for(local_temp_path)) end update(local_path, remote_path, :retrying) diff --git a/bundler/spec/bundler/compact_index_client/updater_spec.rb b/bundler/spec/bundler/compact_index_client/updater_spec.rb index 26159dccd8b7..5ba180a5748c 100644 --- a/bundler/spec/bundler/compact_index_client/updater_spec.rb +++ b/bundler/spec/bundler/compact_index_client/updater_spec.rb @@ -6,25 +6,21 @@ RSpec.describe Bundler::CompactIndexClient::Updater do let(:fetcher) { double(:fetcher) } - let(:local_path) { Pathname("/tmp/localpath") } + let(:local_path) { Pathname.new Dir.mktmpdir("localpath") } let(:remote_path) { double(:remote_path) } let!(:updater) { described_class.new(fetcher) } context "when the ETag header is missing" do # Regression test for https://github.com/rubygems/bundler/issues/5463 + let(:response) { double(:response, :body => "abc123") } - let(:response) { double(:response, :body => "") } - - it "MisMatchedChecksumError is raised" do - # Twice: #update retries on failure - expect(response).to receive(:[]).with("Content-Encoding").twice { "" } - expect(response).to receive(:[]).with("ETag").twice { nil } - expect(fetcher).to receive(:call).twice { response } + it "treats the response as an update" do + expect(response).to receive(:[]).with("Content-Encoding") { "" } + expect(response).to receive(:[]).with("ETag") { nil } + expect(fetcher).to receive(:call) { response } - expect do - updater.update(local_path, remote_path) - end.to raise_error(Bundler::CompactIndexClient::Updater::MisMatchedChecksumError) + updater.update(local_path, remote_path) end end @@ -43,6 +39,7 @@ context "when bundler doesn't have permissions on Dir.tmpdir" do it "Errno::EACCES is raised" do + local_path # create local path before stubbing mktmpdir allow(Dir).to receive(:mktmpdir) { raise Errno::EACCES } expect do