From cf99438f1fb76a689bf6f85d3f835446bc223cec Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 29 Jan 2019 10:07:54 -0800 Subject: [PATCH] Update base path on windows to use common file separator On Windows the File::SEPARATOR ends up being `/` which causes issues with the new way the path is being extracted from the vbox information. When on Windows (even with WSL), automatically convert the path to use common forward slash separator. This fixes path modifications used for storing guest disks. --- .../providers/virtualbox/driver/version_6_0.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_6_0.rb b/plugins/providers/virtualbox/driver/version_6_0.rb index 5f17b6af2..37e783326 100644 --- a/plugins/providers/virtualbox/driver/version_6_0.rb +++ b/plugins/providers/virtualbox/driver/version_6_0.rb @@ -46,7 +46,11 @@ module VagrantPlugins @logger.warn("Failed to locate base path for disks. Using current working directory.") base_path = "." else - base_path = File.dirname(result[:settings_path]) + base_path = result[:settings_path] + if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.wsl? + base_path.gsub!('\\', '/') + end + base_path = File.dirname(base_path) end @logger.info("Base path for disk import: #{base_path}") @@ -61,14 +65,7 @@ module VagrantPlugins disk_params << "--unit" disk_params << unit_num disk_params << "--disk" - 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 occurrence - end + disk_params << path.reverse.sub("/#{suggested_name}/".reverse, "/#{specified_name}/".reverse).reverse # Replace only last occurrence end execute("import", ovf , *name_params, *disk_params, retryable: true) do |type, data|