diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea206be8..e4a5997a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ run. [GH-598] - `vagrant ssh -c` will now send stderr to stderr and stdout to stdout on the host machine, instead of all output to stdout. + - Vagrant can now be interrupted during the "importing" step. ## 0.8.10 (December 10, 2011) diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index abebb6413..01b4ff640 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -21,6 +21,10 @@ module Vagrant # immediately. env[:ui].clear_line + # If we got interrupted, then the import could have been + # interrupted and its not a big deal. Just return out. + return if env[:interrupted] + # Flag as erroneous and return if import failed raise Errors::VMImportFailure if !env[:vm].uuid diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index 0a1786aa8..3ac8a6c52 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -1,4 +1,5 @@ require 'log4r' +require 'vagrant/util/busy' require 'vagrant/util/subprocess' module Vagrant @@ -22,6 +23,9 @@ module Vagrant @logger = Log4r::Logger.new("vagrant::driver::virtualbox") @uuid = uuid + # This flag is used to keep track of interrupted state (SIGINT) + @interrupted = false + if @uuid # Verify the VM exists, and if it doesn't, then don't worry # about it (mark the UUID as nil) @@ -415,7 +419,11 @@ module Vagrant # If the command was a failure, then raise an exception that is # nicely handled by Vagrant. if r.exit_code != 0 - raise Errors::VBoxManageError, :command => command.inspect + if @interrupted + @logger.info("Exit code != 0, but interrupted. Ignoring.") + else + raise Errors::VBoxManageError, :command => command.inspect + end end # Return the output @@ -424,7 +432,14 @@ module Vagrant # Executes a command and returns the raw result object. def raw(*command, &block) - Subprocess.execute("VBoxManage", *command, &block) + int_callback = lambda do + @interrupted = true + @logger.info("Interrupted.") + end + + Util::Busy.busy(int_callback) do + Subprocess.execute("VBoxManage", *command, &block) + end end end end