From becc349846537bcd08e648d4da0e8e4987e0e9ee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 4 Feb 2014 15:51:22 +0100 Subject: [PATCH] core: handle native windows paths like 'c:\foo.box' [GH-2081] --- lib/vagrant/action/builtin/box_add.rb | 15 ++++++++++++--- test/unit/vagrant/action/builtin/box_add_test.rb | 16 ++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 47bfc6f94..891e05145 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -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 diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index 7c2c2d473..b2b31b403 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -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)