core: handle native windows paths like 'c:\foo.box'

[GH-2081]
This commit is contained in:
Mitchell Hashimoto 2014-02-04 15:51:22 +01:00
parent 66a33d846d
commit becc349846
2 changed files with 20 additions and 11 deletions

View File

@ -23,12 +23,21 @@ module Vagrant
@download_interrupted = false
url = Array(env[:box_url]).map do |u|
next u if u =~ /^[a-z0-9]+:.*$/i
u = u.gsub("\\", "/")
if Util::Platform.windows? && u =~ /^[a-z]:/i
# On Windows, we need to be careful about drive letters
u = "file://#{u}"
end
if u =~ /^[a-z0-9]+:.*$/i && !u.start_with?("file://")
# This is not a file URL... carry on
next u
end
# Expand the path and try to use that, if possible
p = File.expand_path(u)
p = File.expand_path(u.gsub(/^file:\/\//, ""))
p = Util::Platform.cygwin_windows_path(p)
next p if File.file?(p)
next "file://#{p}" if File.file?(p)
u
end

View File

@ -361,7 +361,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -405,7 +405,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -454,7 +454,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -494,7 +494,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.5")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -539,7 +539,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.5")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -587,7 +587,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -635,7 +635,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)
@ -812,7 +812,7 @@ describe Vagrant::Action::Builtin::BoxAdd do
expect(name).to eq("foo/bar")
expect(version).to eq("0.7")
expect(opts[:force]).to be_true
expect(opts[:metadata_url]).to eq(tf.path)
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
true
end.and_return(box)