commands/box/add: add --clean flag to ignore continuation

This commit is contained in:
Mitchell Hashimoto 2013-11-23 15:55:52 -08:00
parent b78be4625d
commit 46d9ded812
2 changed files with 16 additions and 3 deletions

View File

@ -35,9 +35,17 @@ module Vagrant
# If the temporary path exists, verify it is not too old. If its # If the temporary path exists, verify it is not too old. If its
# too old, delete it first because the data may have changed. # too old, delete it first because the data may have changed.
if @temp_path.file? && @temp_path.mtime.to_i < (Time.now.to_i - 6 * 60 * 60) if @temp_path.file?
@logger.info("Existing temp file is too old. Removing.") delete = false
@temp_path.unlink if env[:box_clean]
@logger.info("Cleaning existing temp box file.")
delete = true
elsif @temp_path.mtime.to_i < (Time.now.to_i - 6 * 60 * 60)
@logger.info("Existing temp file is too old. Removing.")
delete = true
end
@temp_path.unlink if delete
end end
# Download the box to a temporary path. We store the temporary # Download the box to a temporary path. We store the temporary

View File

@ -11,6 +11,10 @@ module VagrantPlugins
o.banner = "Usage: vagrant box add <name> <url> [--provider provider] [-h]" o.banner = "Usage: vagrant box add <name> <url> [--provider provider] [-h]"
o.separator "" o.separator ""
o.on("-c", "--clean", "Remove old temporary download if it exists.") do |c|
options[:clean] = c
end
o.on("-f", "--force", "Overwrite an existing box if it exists.") do |f| o.on("-f", "--force", "Overwrite an existing box if it exists.") do |f|
options[:force] = f options[:force] = f
end end
@ -38,6 +42,7 @@ module VagrantPlugins
:box_name => argv[0], :box_name => argv[0],
:box_provider => provider, :box_provider => provider,
:box_url => argv[1], :box_url => argv[1],
:box_clean => options[:clean],
:box_force => options[:force], :box_force => options[:force],
:box_download_insecure => options[:insecure], :box_download_insecure => options[:insecure],
}) })