From 5c49d693d403aa34f1120bd2554ca1da82cdc817 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Feb 2012 17:57:23 -0800 Subject: [PATCH] You can no longer output a package to a directory [GH-730] --- CHANGELOG.md | 1 + lib/vagrant/action/general/package.rb | 15 +++++++++------ lib/vagrant/errors.rb | 5 +++++ templates/locales/en.yml | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6bc0bfb..392560de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fix issue with Puppet config inheritance. [GH-722] - Fix issue where starting a VM on some systems was incorrectly treated as failing. [GH-720] + - It is now an error to specify the packaging `output` as a directory. [GH-730] ## 0.9.7 (February 9, 2012) diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index e49d8a439..158fee5f7 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -27,6 +27,7 @@ module Vagrant def call(env) @env = env + raise Errors::PackageOutputDirectory if File.directory?(tar_path) raise Errors::PackageOutputExists if File.exist?(tar_path) raise Errors::PackageRequiresDirectory if !env["package.directory"] || !File.directory?(env["package.directory"]) @@ -37,12 +38,14 @@ module Vagrant end def recover(env) - # Don't delete the tar_path if the error is that the output already - # exists, since this will nuke the user's previous file. - if !env["vagrant.error"].is_a?(Errors::PackageOutputExists) - # Cleanup any packaged files if the packaging failed at some point. - File.delete(tar_path) if File.exist?(tar_path) + # There are certain exceptions that we don't delete the file for. + ignore_exc = [Errors::PackageOutputDirectory, Errors::PackageOutputExists] + ignore_exc.each do |exc| + return if env["vagrant.error"].is_a?(exc) end + + # Cleanup any packaged files if the packaging failed at some point. + File.delete(tar_path) if File.exist?(tar_path) end # This method copies the include files (passed in via command line) @@ -90,7 +93,7 @@ module Vagrant # Path to the final box output file def tar_path - File.join(FileUtils.pwd, @env["package.output"]) + File.expand_path(@env["package.output"], FileUtils.pwd) end end end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 71b98ceb5..1f4a8d8af 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -263,6 +263,11 @@ module Vagrant error_key(:include_file_missing, "vagrant.actions.general.package") end + class PackageOutputDirectory < VagrantError + status_code(72) + error_key(:output_is_directory, "vagrant.actions.general.package") + end + class PackageOutputExists < VagrantError status_code(16) error_key(:output_exists, "vagrant.actions.general.package") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b85da67ad..5d825c07d 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -540,6 +540,9 @@ en: output_exists: |- The specified file to save the package as already exists. Please remove this file or specify a different file name for outputting. + output_is_directory: |- + The specified output is a directory. Please specify a path including + a filename. requires_directory: |- A directory was not specified to package. This should never happen and is a result of an internal inconsistency.