diff --git a/lib/vagrant/downloaders/file.rb b/lib/vagrant/downloaders/file.rb index 0f54c5ec1..829803075 100644 --- a/lib/vagrant/downloaders/file.rb +++ b/lib/vagrant/downloaders/file.rb @@ -6,7 +6,7 @@ module Vagrant # simply does a file copy. class File < Base def self.match?(uri) - ::File.exists?(uri) + ::File.file?(::File.expand_path(uri)) end def prepare(source_url) diff --git a/test/unit/vagrant/downloaders/file_test.rb b/test/unit/vagrant/downloaders/file_test.rb index be5d29cef..170fe8989 100644 --- a/test/unit/vagrant/downloaders/file_test.rb +++ b/test/unit/vagrant/downloaders/file_test.rb @@ -1,5 +1,7 @@ require File.expand_path("../../../base", __FILE__) +require "tempfile" + describe Vagrant::Downloaders::File do let(:ui) { double("ui") } let(:instance) { described_class.new(ui) } @@ -12,6 +14,23 @@ describe Vagrant::Downloaders::File do it "should not match non-existent files" do described_class.match?(File.join(__FILE__, "nowaywaywaywayayway")).should_not be end + + it "should match files where the path needs to be expanded" do + old_home = ENV["HOME"] + begin + # Create a temporary file + temp = Tempfile.new("vagrant") + + # Set our home directory to be this directory so we can use + # "~" paths + ENV["HOME"] = File.dirname(temp.path) + + # Test that we can find the temp file + described_class.match?("~/#{File.basename(temp.path)}").should be + ensure + ENV["HOME"] = old_home + end + end end describe "preparing" do @@ -28,6 +47,24 @@ describe Vagrant::Downloaders::File do expect { instance.prepare(path) }.to raise_error(Vagrant::Errors::DownloaderFileDoesntExist) end + + it "should find files that use shell expansions" do + old_home = ENV["HOME"] + begin + # Create a temporary file + temp = Tempfile.new("vagrant") + + # Set our home directory to be this directory so we can use + # "~" paths + ENV["HOME"] = File.dirname(temp.path) + + # Test that we can find the temp file + expect { instance.prepare("~/#{File.basename(temp.path)}") }. + to_not raise_error + ensure + ENV["HOME"] = old_home + end + end end describe "downloading" do