diff --git a/lib/vagrant/actions/vm/package.rb b/lib/vagrant/actions/vm/package.rb index 4be79d2d9..e67dc6abb 100644 --- a/lib/vagrant/actions/vm/package.rb +++ b/lib/vagrant/actions/vm/package.rb @@ -36,6 +36,21 @@ module Vagrant export_action.temp_dir end + # This method copies the include files (passed in via command line) + # to the temporary directory so they are included in a sub-folder within + # the actual box + def copy_include_files + if include_files.length > 0 + include_dir = File.join(temp_path, "include") + FileUtils.mkdir_p(include_dir) + + include_files.each do |f| + logger.info "Packaging additional file: #{f}" + FileUtils.cp(f, include_dir) + end + end + end + def compress logger.info "Packaging VM into #{tar_path}..." File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar| @@ -43,14 +58,10 @@ module Vagrant begin current_dir = FileUtils.pwd - include_files.each do |f| - logger.info "Packaging additional file: #{f}" - Archive::Tar::Minitar.pack_file(f, output) - end + copy_include_files FileUtils.cd(temp_path) - - Dir.glob(File.join(".", "*")).each do |entry| + Dir.glob(File.join(".", "**", "*")).each do |entry| Archive::Tar::Minitar.pack_file(entry, output) end ensure diff --git a/test/test_helper.rb b/test/test_helper.rb index de72c0c6e..a6e45ddb6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,8 +3,6 @@ begin rescue LoadError # Fallback on doing the resolve at runtime. require "rubygems" - require "bundler" - Bundler.setup end # ruby-debug, not necessary, but useful if we have it diff --git a/test/vagrant/actions/vm/package_test.rb b/test/vagrant/actions/vm/package_test.rb index 92e04badc..31bd2f08e 100644 --- a/test/vagrant/actions/vm/package_test.rb +++ b/test/vagrant/actions/vm/package_test.rb @@ -56,6 +56,37 @@ class PackageActionTest < Test::Unit::TestCase end end + context "copying include files" do + setup do + @include_files = [] + @action.stubs(:include_files).returns(@include_files) + + @temp_path = "foo" + @action.stubs(:temp_path).returns(@temp_path) + end + + should "do nothing if no include files are specified" do + assert @action.include_files.empty? + FileUtils.expects(:mkdir_p).never + FileUtils.expects(:cp).never + @action.copy_include_files + end + + should "create the include directory and copy files to it" do + include_dir = File.join(@action.temp_path, "include") + copy_seq = sequence("copy_seq") + FileUtils.expects(:mkdir_p).with(include_dir).once.in_sequence(copy_seq) + + 5.times do |i| + file = mock("f#{i}") + @include_files << file + FileUtils.expects(:cp).with(file, include_dir).in_sequence(copy_seq) + end + + @action.copy_include_files + end + end + context "compression" do setup do @tar_path = "foo" @@ -98,6 +129,7 @@ class PackageActionTest < Test::Unit::TestCase compress_seq = sequence("compress_seq") FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq) + @action.expects(:copy_include_files).once.in_sequence(compress_seq) FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq) Dir.expects(:glob).returns(@files).in_sequence(compress_seq) @@ -120,25 +152,6 @@ class PackageActionTest < Test::Unit::TestCase @action.compress } end - - should "add included files when passed" do - compress_seq = sequence("compress") - @files = [] - 5.times do |i| - file = mock("file#{i}") - @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq) - @files << file - end - - @action.expects(:include_files).returns(@files) - @action.compress - end - - should "not add files when none are specified" do - @tar.expects(:pack_file).never - Dir.expects(:glob).once.returns([]) - @action.compress - end end context "preparing the action" do