From 446ab32e0e42b04f8e48d9963267f6dd9238d7c6 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sun, 12 Dec 2010 18:23:45 +0100 Subject: [PATCH] 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 --- lib/vagrant/action/general/package.rb | 8 +++++++- test/vagrant/action/general/package_test.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index 8dc5da016..58b36b540 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -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 diff --git a/test/vagrant/action/general/package_test.rb b/test/vagrant/action/general/package_test.rb index 049365d08..be71bbb61 100644 --- a/test/vagrant/action/general/package_test.rb +++ b/test/vagrant/action/general/package_test.rb @@ -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