diff --git a/lib/vagrant/actions/vm/package.rb b/lib/vagrant/actions/vm/package.rb index 6a2dfc5b0..48922dba3 100644 --- a/lib/vagrant/actions/vm/package.rb +++ b/lib/vagrant/actions/vm/package.rb @@ -38,20 +38,24 @@ module Vagrant def compress logger.info "Packaging VM into #{tar_path} ..." - open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar| - begin - current_dir = FileUtils.pwd - @include_files.each do |f| - logger.info "Packaging additional file: #{f}" - Archive::Tar::Minitar.pack(f, tar) + File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar| + Archive::Tar::Minitar::Output.open(tar) do |output| + begin + current_dir = FileUtils.pwd + + include_files.each do |f| + logger.info "Packaging additional file: #{f}" + Archive::Tar::Minitar.pack_file(f, output) + end + + FileUtils.cd(temp_path) + + Dir.glob(File.join(".", "*")).each do |entry| + Archive::Tar::Minitar.pack_file(entry, output) + end + ensure + FileUtils.cd(current_dir) end - - FileUtils.cd(temp_path) - - # Append tree will append the entire directory tree unless a relative folder reference is used - Archive::Tar::Minitar.pack(".", tar) - ensure - FileUtils.cd(current_dir) end end end diff --git a/test/vagrant/actions/box/unpackage_test.rb b/test/vagrant/actions/box/unpackage_test.rb index 1523b3399..84c7b25e9 100644 --- a/test/vagrant/actions/box/unpackage_test.rb +++ b/test/vagrant/actions/box/unpackage_test.rb @@ -84,6 +84,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase @action.stubs(:box_dir).returns(@box_dir) Dir.stubs(:chdir).yields + Archive::Tar::Minitar.stubs(:unpack) end should "change to the box directory" do @@ -92,9 +93,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase end should "open the tar file within the new directory, and extract it all" do - @tar = mock("tar") - @tar.expects(:extract_all).once - Tar.expects(:open).with(@runner.temp_path, anything, anything, anything).yields(@tar) + Archive::Tar::Minitar.expects(:unpack).with(@runner.temp_path, @box_dir).once @action.decompress end end diff --git a/test/vagrant/actions/vm/package_test.rb b/test/vagrant/actions/vm/package_test.rb index 5d9d4e986..b633d3a65 100644 --- a/test/vagrant/actions/vm/package_test.rb +++ b/test/vagrant/actions/vm/package_test.rb @@ -66,27 +66,49 @@ class PackageActionTest < Test::Unit::TestCase @temp_path = "foo" @action.stubs(:temp_path).returns(@temp_path) + @include_files = [] + @action.stubs(:include_files).returns(@include_files) + @pwd = "bar" FileUtils.stubs(:pwd).returns(@pwd) FileUtils.stubs(:cd) - @tar = mock("tar") - Tar.stubs(:open).yields(@tar) + @file = mock("file") + File.stubs(:open).yields(@file) + + @output = mock("output") + @tar = Archive::Tar::Minitar + Archive::Tar::Minitar::Output.stubs(:open).yields(@output) + @tar.stubs(:pack_file) end should "open the tar file with the tar path properly" do - Tar.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU).once + File.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644).once + @action.compress + end + + should "open tar file" do + Archive::Tar::Minitar::Output.expects(:open).with(@file).once @action.compress end #---------------------------------------------------------------- - # Methods below this comment test the block yielded by Tar.open + # Methods below this comment test the block yielded by Minitar open #---------------------------------------------------------------- should "cd to the directory and append the directory" do + @files = [] compress_seq = sequence("compress_seq") + FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq) FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq) - @tar.expects(:append_tree).with(".").in_sequence(compress_seq) + Dir.expects(:glob).returns(@files).in_sequence(compress_seq) + + 5.times do |i| + file = mock("file#{i}") + @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq) + @files << file + end + FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq) @action.compress end @@ -102,17 +124,21 @@ class PackageActionTest < Test::Unit::TestCase end should "add included files when passed" do - include_files = ['foo', 'bar'] - action = mock_action(Vagrant::Actions::VM::Package, "bing", include_files).last - action.stubs(:temp_path).returns("foo") - @tar.expects(:append_tree).with(".") - include_files.each { |f| @tar.expects(:append_file).with(f) } - action.compress + 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(:append_tree).with(".") - @tar.expects(:append_file).never + @tar.expects(:pack_file).never + Dir.expects(:glob).once.returns([]) @action.compress end end