diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index e5d852c20..c516cd22f 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -90,7 +90,7 @@ module Vagrant use VM::ClearSharedFolders use VM::Export use VM::PackageVagrantfile - use VM::Package + use General::Package end register :package, package diff --git a/lib/vagrant/action/vm/package.rb b/lib/vagrant/action/general/package.rb similarity index 77% rename from lib/vagrant/action/vm/package.rb rename to lib/vagrant/action/general/package.rb index 9c0c01e6a..3a2741a0f 100644 --- a/lib/vagrant/action/vm/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -1,6 +1,16 @@ module Vagrant class Action - module VM + module General + # A general packaging (tar) middleware. Given the following options, + # it will do the right thing: + # + # * package.output - The filename of the outputted package. + # * package.include - An array of files to include in the package. + # * package.directory - The directory which contains the contents to + # compress into the package. + # + # This middleware always produces the final file in the current working + # directory (FileUtils.pwd) class Package include Util @@ -9,14 +19,13 @@ module Vagrant @env = env @env["package.output"] ||= env["config"].package.name @env["package.include"] ||= [] - - env.error!(:box_file_exists, :output_file => tar_path) if File.exist?(tar_path) end def call(env) @env = env - return env.error!(:package_requires_export) if !@env["package.directory"] + return env.error!(:package_output_exists) if File.exist?(tar_path) + return env.error!(:package_requires_directory) if !@env["package.directory"] return if !verify_included_files compress diff --git a/templates/strings.yml b/templates/strings.yml index 5d5176cbf..c21799047 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -176,6 +176,13 @@ specific VM must be specified. This can be done by calling `vagrant package NAME` where NAME is a valid VM represented by your Vagrantfile. +:package_output_exists: |- + The specified file to save the package as already exists. Please + remove this file or specify a different filename for outputting. +:package_requires_directory: |- + A directory was not specified to package. This is an internal + issue. Please send the relevant stack trace (if any) and information + about this issue to the Vagrant team. :package_requires_export: |- Package must be used in conjunction with export. :provisioner_invalid_class: |- diff --git a/test/vagrant/action/vm/package_test.rb b/test/vagrant/action/general/package_test.rb similarity index 92% rename from test/vagrant/action/vm/package_test.rb rename to test/vagrant/action/general/package_test.rb index 53d243b99..ee0344bc8 100644 --- a/test/vagrant/action/vm/package_test.rb +++ b/test/vagrant/action/general/package_test.rb @@ -1,15 +1,12 @@ require "test_helper" -class PackageVMActionTest < Test::Unit::TestCase +class PackageGeneralActionTest < Test::Unit::TestCase setup do - @klass = Vagrant::Action::VM::Package + @klass = Vagrant::Action::General::Package @app, @env = mock_action_data @vm = mock("vm") @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) end context "initializing" do @@ -24,13 +21,6 @@ class PackageVMActionTest < Test::Unit::TestCase assert !@env.error? end - should "error the environment if the output file exists" do - File.stubs(:exist?).with(@tar_path).returns(true) - @klass.new(@app, @env) - assert @env.error? - assert_equal :box_file_exists, @env.error.first - end - should "set the output path to configured by default" do @klass.new(@app, @env) assert_equal @env["config"].package.name, @env["package.output"] @@ -81,13 +71,22 @@ class PackageVMActionTest < Test::Unit::TestCase @instance.call(@env) end - should "halt the chain if export didn't run" do + should "halt the chain if the output file already exists" do + File.expects(:exist?).returns(true) + @app.expects(:call).never + @instance.call(@env) + + assert @env.error? + assert_equal :package_output_exists, @env.error.first + end + + should "halt the chain if directory isn't set" do @env["package.directory"] = nil @app.expects(:call).never @instance.call(@env) assert @env.error? - assert_equal :package_requires_export, @env.error.first + assert_equal :package_requires_directory, @env.error.first end should "run cleanup if environment errors" do