From 46d9ded812fefd48e61f291f0463edad3598b3fd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 23 Nov 2013 15:55:52 -0800 Subject: [PATCH] commands/box/add: add --clean flag to ignore continuation --- lib/vagrant/action/builtin/box_add.rb | 14 +++++++++++--- plugins/commands/box/command/add.rb | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index a6c44e8d4..01adb0e18 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -35,9 +35,17 @@ module Vagrant # If the temporary path exists, verify it is not too old. If its # 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) - @logger.info("Existing temp file is too old. Removing.") - @temp_path.unlink + if @temp_path.file? + delete = false + 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 # Download the box to a temporary path. We store the temporary diff --git a/plugins/commands/box/command/add.rb b/plugins/commands/box/command/add.rb index 7f6829c7d..1f5f9be5f 100644 --- a/plugins/commands/box/command/add.rb +++ b/plugins/commands/box/command/add.rb @@ -11,6 +11,10 @@ module VagrantPlugins o.banner = "Usage: vagrant box add [--provider provider] [-h]" 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| options[:force] = f end @@ -38,6 +42,7 @@ module VagrantPlugins :box_name => argv[0], :box_provider => provider, :box_url => argv[1], + :box_clean => options[:clean], :box_force => options[:force], :box_download_insecure => options[:insecure], })