diff --git a/lib/vagrant/actions/box/download.rb b/lib/vagrant/actions/box/download.rb index 5692afb3e..5db98f8ea 100644 --- a/lib/vagrant/actions/box/download.rb +++ b/lib/vagrant/actions/box/download.rb @@ -48,7 +48,7 @@ module Vagrant def with_tempfile logger.info "Creating tempfile for storing box file..." - # create, write only, fail if the file exists + # create, write only, fail if the file exists File.open(box_temp_path, File::WRONLY|File::EXCL|File::CREAT) do |tempfile| yield tempfile end diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index 4f1dd6968..49bb75ffd 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -8,7 +8,8 @@ module Vagrant def self.match?(uri) # URI.parse barfs on ':\\files \on\ windows' - URI.extract(uri).first.include?(uri) + uri = URI.extract(uri).first + uri && uri.include?(uri) end def download!(source_url, destination_file) diff --git a/test/vagrant/actions/box/download_test.rb b/test/vagrant/actions/box/download_test.rb index 9df977b05..a7b165318 100644 --- a/test/vagrant/actions/box/download_test.rb +++ b/test/vagrant/actions/box/download_test.rb @@ -89,7 +89,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase context "tempfile" do should "create a tempfile in the vagrant tmp directory" do File.expects(:open).with { |name, bitmask| - name =~ /#{Vagrant::Actions::Box::Download::BASENAME}/ && name =~ /#{@runner.env.tmp_path}/ + name =~ /#{Vagrant::Actions::Box::Download::BASENAME}/ && name =~ /#{@runner.env.tmp_path}/ }.once @action.with_tempfile end diff --git a/test/vagrant/downloaders/http_test.rb b/test/vagrant/downloaders/http_test.rb index 88dfdf663..4730ed13a 100644 --- a/test/vagrant/downloaders/http_test.rb +++ b/test/vagrant/downloaders/http_test.rb @@ -39,6 +39,11 @@ class HttpDownloaderTest < Test::Unit::TestCase URI.expects(:extract).returns(['foo']) assert Vagrant::Downloaders::HTTP.match?('foo') end + + should "return false if there are no extract results" do + URI.expects(:extract).returns([]) + assert !Vagrant::Downloaders::HTTP.match?('foo') + end end context "reporting progress" do