From bf2e8deebeb521c80b565b98e18dffd586e53fd3 Mon Sep 17 00:00:00 2001 From: Akzhan Abdulin Date: Tue, 24 Jun 2014 13:26:40 +0400 Subject: [PATCH 1/3] VirtualBox driver should replace only last occurence of suggested VM name. --- plugins/providers/virtualbox/driver/version_4_2.rb | 12 ++++++------ plugins/providers/virtualbox/driver/version_4_3.rb | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index 94325fe70..8bec8acca 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -180,12 +180,12 @@ module VagrantPlugins disk_params = Array.new disks = output.scan(/(\d+): Hard disk image: source image=.+, target path=(.+),/) disks.each do |unit_num, path| - disk_params << "--vsys" - disk_params << "0" #Derive vsys num .. do we support OVF's with multiple machines? - disk_params << "--unit" - disk_params << unit_num - disk_params << "--disk" - disk_params << path.sub("/#{suggested_name}/", "/#{specified_name}/") + disk_params << "--vsys" + disk_params << "0" #Derive vsys num .. do we support OVF's with multiple machines? + disk_params << "--unit" + disk_params << unit_num + disk_params << "--disk" + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence end execute("import", ovf , *name_params, *disk_params) do |type, data| diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 74ddb4474..5c7deb031 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -188,12 +188,12 @@ module VagrantPlugins disk_params = [] disks = output.scan(/(\d+): Hard disk image: source image=.+, target path=(.+),/) disks.each do |unit_num, path| - disk_params << "--vsys" - disk_params << "0" - disk_params << "--unit" - disk_params << unit_num - disk_params << "--disk" - disk_params << path.sub("/#{suggested_name}/", "/#{specified_name}/") + disk_params << "--vsys" + disk_params << "0" + disk_params << "--unit" + disk_params << unit_num + disk_params << "--disk" + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence end execute("import", ovf , *name_params, *disk_params) do |type, data| From 0912ddaf5fd1853e6094b45dbb3144e9b358efa0 Mon Sep 17 00:00:00 2001 From: Keith Shook Date: Tue, 1 Jul 2014 09:00:23 -0400 Subject: [PATCH 2/3] Ensure VirtualBox virtual disks are stored in the correct directory on Windows hosts --- plugins/providers/virtualbox/driver/version_4_2.rb | 6 +++++- plugins/providers/virtualbox/driver/version_4_3.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index 8bec8acca..de8a16733 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -185,7 +185,11 @@ module VagrantPlugins disk_params << "--unit" disk_params << unit_num disk_params << "--disk" - disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + if Gem.win_platform? + disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse, "\\#{specified_name}\\".reverse).reverse # Replace only last occurence + else + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + end end execute("import", ovf , *name_params, *disk_params) do |type, data| diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 5c7deb031..d83b0adf6 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -193,7 +193,11 @@ module VagrantPlugins disk_params << "--unit" disk_params << unit_num disk_params << "--disk" - disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + if Gem.win_platform? + disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse, "\\#{specified_name}\\".reverse).reverse # Replace only last occurence + else + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + end end execute("import", ovf , *name_params, *disk_params) do |type, data| From 93f84f53e599c8637573faf16e596a5bae730ad3 Mon Sep 17 00:00:00 2001 From: Keith Shook Date: Wed, 2 Jul 2014 10:08:44 -0400 Subject: [PATCH 3/3] Ensure VirtualBox virtual disks are stored in the correct directory round 2 --- plugins/providers/virtualbox/driver/version_4_2.rb | 9 ++++++--- plugins/providers/virtualbox/driver/version_4_3.rb | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index de8a16733..cbc397f3e 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -185,10 +185,13 @@ module VagrantPlugins disk_params << "--unit" disk_params << unit_num disk_params << "--disk" - if Gem.win_platform? - disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse, "\\#{specified_name}\\".reverse).reverse # Replace only last occurence + if Vagrant::Util::Platform.windows? + # we use the block form of sub here to ensure that if the specified_name happens to end with a number (which is fairly likely) then + # we won't end up having the character sequence of a \ followed by a number be interpreted as a back reference. For example, if + # specified_name were "abc123", then "\\abc123\\".reverse would be "\\321cba\\", and the \3 would be treated as a back reference by the sub + disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse) { "\\#{specified_name}\\".reverse }.reverse # Replace only last occurrence else - disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurrence end end diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index d83b0adf6..14d12704a 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -193,10 +193,13 @@ module VagrantPlugins disk_params << "--unit" disk_params << unit_num disk_params << "--disk" - if Gem.win_platform? - disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse, "\\#{specified_name}\\".reverse).reverse # Replace only last occurence + if Vagrant::Util::Platform.windows? + # we use the block form of sub here to ensure that if the specified_name happens to end with a number (which is fairly likely) then + # we won't end up having the character sequence of a \ followed by a number be interpreted as a back reference. For example, if + # specified_name were "abc123", then "\\abc123\\".reverse would be "\\321cba\\", and the \3 would be treated as a back reference by the sub + disk_params << path.reverse.sub("\\#{suggested_name}\\".reverse) { "\\#{specified_name}\\".reverse }.reverse # Replace only last occurrence else - disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurence + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurrence end end