core: can add/search boxes with slashes in name

This commit is contained in:
Mitchell Hashimoto 2014-01-23 10:57:57 -08:00
parent 96e92167d9
commit 15aa91b073
2 changed files with 33 additions and 5 deletions

View File

@ -153,7 +153,7 @@ module Vagrant
provider = box_provider.to_sym provider = box_provider.to_sym
# Create the directory for this box, not including the provider # Create the directory for this box, not including the provider
box_dir = @directory.join(name, version) box_dir = @directory.join(dir_name(name), version)
box_dir.mkpath box_dir.mkpath
@logger.debug("Box directory: #{box_dir}") @logger.debug("Box directory: #{box_dir}")
@ -198,7 +198,7 @@ module Vagrant
# us in our folder structure. # us in our folder structure.
next if !child.directory? next if !child.directory?
box_name = child.basename.to_s box_name = undir_name(child.basename.to_s)
# Otherwise, traverse the subdirectories and see what versions # Otherwise, traverse the subdirectories and see what versions
# we have. # we have.
@ -239,7 +239,7 @@ module Vagrant
end end
with_collection_lock do with_collection_lock do
box_directory = @directory.join(name) box_directory = @directory.join(dir_name(name))
if !box_directory.directory? if !box_directory.directory?
@logger.info("Box not found: #{name} (#{providers.join(", ")})") @logger.info("Box not found: #{name} (#{providers.join(", ")})")
return nil return nil
@ -284,7 +284,7 @@ module Vagrant
end end
# Create the directory for this box # Create the directory for this box
new_box_dir = temp_dir.join(box_name, "0") new_box_dir = temp_dir.join(dir_name(box_name), "0")
new_box_dir.mkpath new_box_dir.mkpath
# Go through each provider and move it # Go through each provider and move it
@ -301,6 +301,19 @@ module Vagrant
protected protected
# Returns the directory name for the box of the given name.
#
# @param [String] name
# @return [String]
def dir_name(name)
name.gsub("/", "-VAGRANTSLASH-")
end
# Returns the directory name for the box cleaned up
def undir_name(name)
name.gsub("-VAGRANTSLASH-", "/")
end
# This checks if the given directory represents a V1 box on the # This checks if the given directory represents a V1 box on the
# system. # system.
# #

View File

@ -25,13 +25,15 @@ describe Vagrant::BoxCollection do
environment.box3("foo", "1.0", :virtualbox) environment.box3("foo", "1.0", :virtualbox)
environment.box3("foo", "1.0", :vmware) environment.box3("foo", "1.0", :vmware)
environment.box3("bar", "0", :ec2) environment.box3("bar", "0", :ec2)
environment.box3("foo-VAGRANTSLASH-bar", "1.0", :virtualbox)
# Verify some output # Verify some output
results = subject.all results = subject.all
results.length.should == 3 results.length.should == 4
results.include?(["foo", "1.0", :virtualbox]).should be results.include?(["foo", "1.0", :virtualbox]).should be
results.include?(["foo", "1.0", :vmware]).should be results.include?(["foo", "1.0", :vmware]).should be
results.include?(["bar", "0", :ec2]).should be results.include?(["bar", "0", :ec2]).should be
results.include?(["foo/bar", "1.0", :virtualbox]).should be
end end
it 'does not raise an exception when a file appears in the boxes dir' do it 'does not raise an exception when a file appears in the boxes dir' do
@ -96,6 +98,19 @@ describe Vagrant::BoxCollection do
expect(subject.find("foo", :virtualbox, "1.0")).to_not be_nil expect(subject.find("foo", :virtualbox, "1.0")).to_not be_nil
end end
it "should add a box with a name with '/' in it" do
box_path = environment.box2_file(:virtualbox)
# Add the box
box = subject.add(box_path, "foo/bar", "1.0")
expect(box).to be_kind_of(box_class)
expect(box.name).to eq("foo/bar")
expect(box.provider).to eq(:virtualbox)
# Verify we can find it as well
expect(subject.find("foo/bar", :virtualbox, "1.0")).to_not be_nil
end
it "should add a box without specifying a provider" do it "should add a box without specifying a provider" do
box_path = environment.box2_file(:vmware) box_path = environment.box2_file(:vmware)