From 50c04ac9276e3886de41230f1e870fdfc1f6ab77 Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Fri, 24 Aug 2012 09:53:50 -0400 Subject: [PATCH] `box.url` can use `file://` URI --- lib/vagrant/downloaders/file.rb | 4 +++- lib/vagrant/downloaders/http.rb | 2 +- test/unit/vagrant/downloaders/file_test.rb | 4 ++++ test/unit/vagrant/downloaders/http_test.rb | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/downloaders/file.rb b/lib/vagrant/downloaders/file.rb index 63ca0ba56..9521bae45 100644 --- a/lib/vagrant/downloaders/file.rb +++ b/lib/vagrant/downloaders/file.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'uri' module Vagrant module Downloaders @@ -6,7 +7,8 @@ module Vagrant # simply does a file copy. class File < Base def self.match?(uri) - ::File.file?(::File.expand_path(uri)) + extracted = URI.extract(uri, "file") + (extracted && extracted.include?(uri)) || ::File.file?(::File.expand_path(uri)) end def download!(source_url, destination_file) diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index 5e4d10cbb..3f005100c 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -10,7 +10,7 @@ module Vagrant class HTTP < Base def self.match?(uri) # URI.parse barfs on ':\\files \on\ windows' - extracted = URI.extract(uri).first + extracted = URI.extract(uri, ['http', 'https']).first extracted && extracted.include?(uri) end diff --git a/test/unit/vagrant/downloaders/file_test.rb b/test/unit/vagrant/downloaders/file_test.rb index ad4fb3f03..a9b8ff986 100644 --- a/test/unit/vagrant/downloaders/file_test.rb +++ b/test/unit/vagrant/downloaders/file_test.rb @@ -37,6 +37,10 @@ describe Vagrant::Downloaders::File do ENV["HOME"] = old_home end end + + it "should match file:// URIs" do + described_class.match?("file://#{__FILE__}").should be + end end describe "downloading" do diff --git a/test/unit/vagrant/downloaders/http_test.rb b/test/unit/vagrant/downloaders/http_test.rb index dfd8782b9..3951b0cec 100644 --- a/test/unit/vagrant/downloaders/http_test.rb +++ b/test/unit/vagrant/downloaders/http_test.rb @@ -11,6 +11,10 @@ describe Vagrant::Downloaders::HTTP do described_class.match?("http://foo:bar@google.com/foo.box").should be described_class.match?("http://google.com:8500/foo.box").should be end + + it "should not match file:// URIs" do + described_class.match?("file://#{__FILE__}").should_not be + end end describe "downloading" do