Allow to recursively include files when packaging a box

This allows to bundle with a box a set of puppet manifests or chef cookbooks.
This supports both shell globbing and recursive copy of full directories.

Usage:

vagrant package ... --include=manifests
This would bundle the whole manifests/ directory

vagrant package ... --include=id*
This would bundle all files with prefix id in the produced box

Signed-off-by: Brice Figureau <brice@daysofwonder.com>
This commit is contained in:
Brice Figureau 2010-12-12 18:23:45 +01:00 committed by Mitchell Hashimoto
parent f0d1631528
commit 446ab32e0e
2 changed files with 21 additions and 1 deletions

View File

@ -68,7 +68,13 @@ module Vagrant
files_to_copy.each do |from, to|
@env.ui.info I18n.t("vagrant.actions.general.package.packaging", :file => from)
FileUtils.mkdir_p(to.parent)
FileUtils.cp(from, to)
# Copy direcotry contents recursively.
if File.directory?(from)
FileUtils.cp_r(Dir.glob(from), to.parent)
else
FileUtils.cp(from, to)
end
end
end

View File

@ -173,11 +173,25 @@ class PackageGeneralActionTest < Test::Unit::TestCase
seq = sequence("seq")
@instance.files_to_copy.each do |from, to|
FileUtils.expects(:mkdir_p).with(to.parent).in_sequence(seq)
File.expects(:directory?).with(from).returns(false).in_sequence(seq)
FileUtils.expects(:cp).with(from, to).in_sequence(seq)
end
@instance.copy_include_files
end
should "create the include directory and recursively copy globbed files to it" do
@env["package.include"] = ["foo*.txt"]
seq = sequence("seq")
@instance.files_to_copy.each do |from, to|
FileUtils.expects(:mkdir_p).with(to.parent).in_sequence(seq)
File.expects(:directory?).with(from).returns(true).in_sequence(seq)
Dir.expects(:glob).with(from).returns(from).in_sequence(seq)
FileUtils.expects(:cp_r).with(from, to.parent).in_sequence(seq)
end
@instance.copy_include_files
end
end
context "compression" do