You can no longer output a package to a directory [GH-730]

This commit is contained in:
Mitchell Hashimoto 2012-02-10 17:57:23 -08:00
parent 99ec766efe
commit 5c49d693d4
4 changed files with 18 additions and 6 deletions

View File

@ -13,6 +13,7 @@
- Fix issue with Puppet config inheritance. [GH-722] - Fix issue with Puppet config inheritance. [GH-722]
- Fix issue where starting a VM on some systems was incorrectly treated - Fix issue where starting a VM on some systems was incorrectly treated
as failing. [GH-720] 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) ## 0.9.7 (February 9, 2012)

View File

@ -27,6 +27,7 @@ module Vagrant
def call(env) def call(env)
@env = env @env = env
raise Errors::PackageOutputDirectory if File.directory?(tar_path)
raise Errors::PackageOutputExists if File.exist?(tar_path) raise Errors::PackageOutputExists if File.exist?(tar_path)
raise Errors::PackageRequiresDirectory if !env["package.directory"] || raise Errors::PackageRequiresDirectory if !env["package.directory"] ||
!File.directory?(env["package.directory"]) !File.directory?(env["package.directory"])
@ -37,12 +38,14 @@ module Vagrant
end end
def recover(env) def recover(env)
# Don't delete the tar_path if the error is that the output already # There are certain exceptions that we don't delete the file for.
# exists, since this will nuke the user's previous file. ignore_exc = [Errors::PackageOutputDirectory, Errors::PackageOutputExists]
if !env["vagrant.error"].is_a?(Errors::PackageOutputExists) ignore_exc.each do |exc|
# Cleanup any packaged files if the packaging failed at some point. return if env["vagrant.error"].is_a?(exc)
File.delete(tar_path) if File.exist?(tar_path)
end end
# Cleanup any packaged files if the packaging failed at some point.
File.delete(tar_path) if File.exist?(tar_path)
end end
# This method copies the include files (passed in via command line) # This method copies the include files (passed in via command line)
@ -90,7 +93,7 @@ module Vagrant
# Path to the final box output file # Path to the final box output file
def tar_path def tar_path
File.join(FileUtils.pwd, @env["package.output"]) File.expand_path(@env["package.output"], FileUtils.pwd)
end end
end end
end end

View File

@ -263,6 +263,11 @@ module Vagrant
error_key(:include_file_missing, "vagrant.actions.general.package") error_key(:include_file_missing, "vagrant.actions.general.package")
end end
class PackageOutputDirectory < VagrantError
status_code(72)
error_key(:output_is_directory, "vagrant.actions.general.package")
end
class PackageOutputExists < VagrantError class PackageOutputExists < VagrantError
status_code(16) status_code(16)
error_key(:output_exists, "vagrant.actions.general.package") error_key(:output_exists, "vagrant.actions.general.package")

View File

@ -540,6 +540,9 @@ en:
output_exists: |- output_exists: |-
The specified file to save the package as already exists. Please The specified file to save the package as already exists. Please
remove this file or specify a different file name for outputting. 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: |- requires_directory: |-
A directory was not specified to package. This should never happen A directory was not specified to package. This should never happen
and is a result of an internal inconsistency. and is a result of an internal inconsistency.