From cd3035e5e9ec65d9c617846d693cb42dbded1496 Mon Sep 17 00:00:00 2001 From: Alexey Kamenskiy Date: Tue, 11 Oct 2016 18:21:39 +0800 Subject: [PATCH 1/3] Issue #7885 Don't raise error if response is 416 416 means there is no more bytes to download (which works only with `--continue-at -` of curl) --- lib/vagrant/util/downloader.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index d9eace0c1..425160259 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -294,9 +294,13 @@ module Vagrant @logger.warn("Downloader exit code: #{result.exit_code}") parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2) parts[1] ||= "" - raise Errors::DownloaderError, - code: result.exit_code, - message: parts[1].chomp + if parts[1].include? "416" + # All good actually. 416 means there is no mory bytes to download + else + raise Errors::DownloaderError, + code: result.exit_code, + message: parts[1].chomp + end end result From f1993dfa191ee2b98e7d6f64e473a8b199ba113f Mon Sep 17 00:00:00 2001 From: Alexey Kamenskiy Date: Thu, 27 Oct 2016 10:06:27 +0800 Subject: [PATCH 2/3] Fixed minor typo in comment --- lib/vagrant/util/downloader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index 425160259..f19d3ffef 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -295,7 +295,7 @@ module Vagrant parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2) parts[1] ||= "" if parts[1].include? "416" - # All good actually. 416 means there is no mory bytes to download + # All good actually. 416 means there is no more bytes to download else raise Errors::DownloaderError, code: result.exit_code, From 67c3f866ddf6ac6e206c122083f7fe1e597a75a0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 25 Apr 2018 13:32:39 -0700 Subject: [PATCH 3/3] (#7886) Add tests and simplify code for continuing on 416 --- lib/vagrant/util/downloader.rb | 14 ++++++++++---- test/unit/vagrant/util/downloader_test.rb | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index f19d3ffef..285f83b75 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -292,14 +292,20 @@ module Vagrant # show an error message. if result.exit_code != 0 @logger.warn("Downloader exit code: #{result.exit_code}") - parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2) - parts[1] ||= "" - if parts[1].include? "416" + check = result.stderr.match(/\n*curl:\s+\((?\d+)\)\s*(?.*)$/) + if check && check[:code] == "416" # All good actually. 416 means there is no more bytes to download + @logger.warn("Downloader got a 416, but is likely fine. Continuing on...") else + if !check + err_msg = result.stderr + else + err_msg = check[:error] + end + raise Errors::DownloaderError, code: result.exit_code, - message: parts[1].chomp + message: err_msg end end diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 772412fbc..b335fe685 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -41,6 +41,20 @@ describe Vagrant::Util::Downloader do context "with a bad exit status" do let(:exit_code) { 1 } + let(:subprocess_result_416) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(exit_code) + allow(result).to receive(:stderr).and_return("curl: (416) The download is fine") + end + end + + it "continues on if a 416 was received" do + expect(Vagrant::Util::Subprocess).to receive(:execute). + with("curl", *curl_options). + and_return(subprocess_result_416) + + expect(subject.download!).to be(true) + end it "raises an exception" do expect(Vagrant::Util::Subprocess).to receive(:execute).