From 73eb86bad0f87cc7f6ab4dd81e3013728d29e408 Mon Sep 17 00:00:00 2001 From: John Barney Date: Sat, 9 Feb 2013 19:36:56 -0800 Subject: [PATCH 1/6] Adding Cygwin detection, and fixing pathing issue in VirtualBox driver under Cygwin --- lib/vagrant/util/platform.rb | 4 ++++ plugins/providers/virtualbox/action/import.rb | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index a55c4f61c..51c3ad494 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -14,6 +14,10 @@ module Vagrant platform.include?("darwin9") end + def cygwin? + platform.include?("cygwin") + end + [:darwin, :bsd, :freebsd, :linux, :solaris].each do |type| define_method("#{type}?") do platform.include?(type.to_s) diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index 14ac2b0bb..e4b155914 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -12,7 +12,10 @@ module VagrantPlugins # Import the virtual machine ovf_file = env[:machine].box.directory.join("box.ovf").to_s - env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| + if Vagrant::Util::Platform.cygwin? + ovf_file = `cygpath -w #{ovf_file}`.chomp + end + env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| env[:ui].clear_line env[:ui].report_progress(progress, 100, false) end From cea8c5dafd13c651799bb6c7afd0fcb5ff768c8a Mon Sep 17 00:00:00 2001 From: John Barney Date: Sat, 9 Feb 2013 19:42:04 -0800 Subject: [PATCH 2/6] Whitespace issue fixed --- plugins/providers/virtualbox/action/import.rb | 2 +- .../providers/virtualbox/action/import.rb~ | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 plugins/providers/virtualbox/action/import.rb~ diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index e4b155914..cd614575c 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -15,7 +15,7 @@ module VagrantPlugins if Vagrant::Util::Platform.cygwin? ovf_file = `cygpath -w #{ovf_file}`.chomp end - env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| + env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| env[:ui].clear_line env[:ui].report_progress(progress, 100, false) end diff --git a/plugins/providers/virtualbox/action/import.rb~ b/plugins/providers/virtualbox/action/import.rb~ new file mode 100644 index 000000000..e4b155914 --- /dev/null +++ b/plugins/providers/virtualbox/action/import.rb~ @@ -0,0 +1,54 @@ +module VagrantPlugins + module ProviderVirtualBox + module Action + class Import + def initialize(app, env) + @app = app + end + + def call(env) + env[:ui].info I18n.t("vagrant.actions.vm.import.importing", + :name => env[:machine].box.name) + + # Import the virtual machine + ovf_file = env[:machine].box.directory.join("box.ovf").to_s + if Vagrant::Util::Platform.cygwin? + ovf_file = `cygpath -w #{ovf_file}`.chomp + end + env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| + env[:ui].clear_line + env[:ui].report_progress(progress, 100, false) + end + + # Clear the line one last time since the progress meter doesn't disappear + # 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 Vagrant::Errors::VMImportFailure if !env[:machine].id + + # Import completed successfully. Continue the chain + @app.call(env) + end + + def recover(env) + if env[:machine].provider.state.id != :not_created + return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) + + # Interrupted, destroy the VM. We note that we don't want to + # validate the configuration here, and we don't want to confirm + # we want to destroy. + destroy_env = env.clone + destroy_env[:config_validate] = false + destroy_env[:force_confirm_destroy] = true + env[:action_runner].run(Action.action_destroy, destroy_env) + end + end + end + end + end +end From e0949085a0818803eb17bfec59b69c2a47b7f0ea Mon Sep 17 00:00:00 2001 From: John Barney Date: Sun, 10 Feb 2013 01:40:59 -0800 Subject: [PATCH 3/6] No longer need VBoxmanage.exe to be in PATH in Cygwin. --- plugins/providers/virtualbox/driver/base.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 5dfb23aa5..f887552fb 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -25,7 +25,7 @@ module VagrantPlugins # Set the path to VBoxManage @vboxmanage_path = "VBoxManage" - if Vagrant::Util::Platform.windows? + if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.cygwin? @logger.debug("Windows. Trying VBOX_INSTALL_PATH for VBoxManage") # On Windows, we use the VBOX_INSTALL_PATH environmental @@ -33,6 +33,9 @@ module VagrantPlugins if ENV.has_key?("VBOX_INSTALL_PATH") # Get the path. path = ENV["VBOX_INSTALL_PATH"] + if Vagrant::Util::Platform.cygwin? + path = `cygpath -u '#{path}'`.chomp + end @logger.debug("VBOX_INSTALL_PATH value: #{path}") # There can actually be multiple paths in here, so we need to @@ -44,7 +47,7 @@ module VagrantPlugins # If the executable exists, then set it as the main path # and break out vboxmanage = "#{path}VBoxManage.exe" - if File.file?(vboxmanage) + if File.file?(vboxmanage) @vboxmanage_path = vboxmanage break end From 52156d7c0687be2d8ea1c42fedc6b218db4cf1da Mon Sep 17 00:00:00 2001 From: John Barney Date: Sun, 10 Feb 2013 01:41:15 -0800 Subject: [PATCH 4/6] Solved bug with spaces in paths causing errors --- plugins/providers/virtualbox/action/import.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index cd614575c..0dfd52f89 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -13,7 +13,7 @@ module VagrantPlugins # Import the virtual machine ovf_file = env[:machine].box.directory.join("box.ovf").to_s if Vagrant::Util::Platform.cygwin? - ovf_file = `cygpath -w #{ovf_file}`.chomp + ovf_file = `cygpath -m '#{ovf_file}'`.chomp end env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| env[:ui].clear_line From 416a76541742997c684158d213e27b420e3a9106 Mon Sep 17 00:00:00 2001 From: John Barney Date: Sun, 10 Feb 2013 01:43:49 -0800 Subject: [PATCH 5/6] Removing extra file --- .../providers/virtualbox/action/import.rb~ | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 plugins/providers/virtualbox/action/import.rb~ diff --git a/plugins/providers/virtualbox/action/import.rb~ b/plugins/providers/virtualbox/action/import.rb~ deleted file mode 100644 index e4b155914..000000000 --- a/plugins/providers/virtualbox/action/import.rb~ +++ /dev/null @@ -1,54 +0,0 @@ -module VagrantPlugins - module ProviderVirtualBox - module Action - class Import - def initialize(app, env) - @app = app - end - - def call(env) - env[:ui].info I18n.t("vagrant.actions.vm.import.importing", - :name => env[:machine].box.name) - - # Import the virtual machine - ovf_file = env[:machine].box.directory.join("box.ovf").to_s - if Vagrant::Util::Platform.cygwin? - ovf_file = `cygpath -w #{ovf_file}`.chomp - end - env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) - end - - # Clear the line one last time since the progress meter doesn't disappear - # 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 Vagrant::Errors::VMImportFailure if !env[:machine].id - - # Import completed successfully. Continue the chain - @app.call(env) - end - - def recover(env) - if env[:machine].provider.state.id != :not_created - return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) - - # Interrupted, destroy the VM. We note that we don't want to - # validate the configuration here, and we don't want to confirm - # we want to destroy. - destroy_env = env.clone - destroy_env[:config_validate] = false - destroy_env[:force_confirm_destroy] = true - env[:action_runner].run(Action.action_destroy, destroy_env) - end - end - end - end - end -end From a390b9dddff739584f02986c2391fe07cf316d27 Mon Sep 17 00:00:00 2001 From: John Barney Date: Sun, 10 Feb 2013 03:49:15 -0800 Subject: [PATCH 6/6] Removing tabs added by a bad .vimrc --- lib/vagrant/util/platform.rb | 2 +- plugins/providers/virtualbox/driver/base.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 51c3ad494..c3b16d083 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -15,7 +15,7 @@ module Vagrant end def cygwin? - platform.include?("cygwin") + platform.include?("cygwin") end [:darwin, :bsd, :freebsd, :linux, :solaris].each do |type| diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index f887552fb..e7cc2e035 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -35,7 +35,7 @@ module VagrantPlugins path = ENV["VBOX_INSTALL_PATH"] if Vagrant::Util::Platform.cygwin? path = `cygpath -u '#{path}'`.chomp - end + end @logger.debug("VBOX_INSTALL_PATH value: #{path}") # There can actually be multiple paths in here, so we need to @@ -47,7 +47,7 @@ module VagrantPlugins # If the executable exists, then set it as the main path # and break out vboxmanage = "#{path}VBoxManage.exe" - if File.file?(vboxmanage) + if File.file?(vboxmanage) @vboxmanage_path = vboxmanage break end