diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 6e9f993f3..3c0ecf420 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -392,6 +392,7 @@ module Vagrant # @param [String, Pathname] path Path to convert # @return [String] def wsl_to_windows_path(path) + path = path.to_s if wsl? && wsl_windows_access? && !path.match(/^[a-zA-Z]:/) if wsl_path?(path) parts = path.split("/") diff --git a/plugins/providers/hyperv/action/export.rb b/plugins/providers/hyperv/action/export.rb index d3d8929ed..28b5ab4be 100644 --- a/plugins/providers/hyperv/action/export.rb +++ b/plugins/providers/hyperv/action/export.rb @@ -23,7 +23,8 @@ module VagrantPlugins def export @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting") - @env[:machine].provider.driver.export(@env["export.temp_dir"]) do |progress| + export_tmp_dir = Vagrant::Util::Platform.wsl_to_windows_path(@env["export.temp_dir"]) + @env[:machine].provider.driver.export(export_tmp_dir) do |progress| @env[:ui].clear_line @env[:ui].report_progress(progress.percent, 100, false) end diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index 25229e3d0..afec6f39a 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -61,11 +61,11 @@ module VagrantPlugins dest_path = env[:machine].data_dir.join("Virtual Hard Disks").join(image_path.basename).to_s options = { - "VMConfigFile" => config_path.to_s.gsub("/", "\\"), - "DestinationPath" => dest_path.to_s.gsub("/", "\\"), - "DataPath" => env[:machine].data_dir.to_s.gsub("/", "\\"), + "VMConfigFile" => Vagrant::Util::Platform.wsl_to_windows_path(config_path).gsub("/", "\\"), + "DestinationPath" => Vagrant::Util::Platform.wsl_to_windows_path(dest_path).gsub("/", "\\"), + "DataPath" => Vagrant::Util::Platform.wsl_to_windows_path(env[:machine].data_dir).gsub("/", "\\"), "LinkedClone" => !!env[:machine].provider_config.linked_clone, - "SourcePath" => image_path.to_s.gsub("/", "\\"), + "SourcePath" => Vagrant::Util::Platform.wsl_to_windows_path(image_path).gsub("/", "\\"), "VMName" => env[:machine].provider_config.vmname, } diff --git a/plugins/providers/hyperv/driver.rb b/plugins/providers/hyperv/driver.rb index 04efa3eb1..ff3fe98a3 100644 --- a/plugins/providers/hyperv/driver.rb +++ b/plugins/providers/hyperv/driver.rb @@ -221,8 +221,8 @@ module VagrantPlugins def execute_powershell(path, options, &block) lib_path = Pathname.new(File.expand_path("../scripts", __FILE__)) - mod_path = lib_path.join("utils").to_s.gsub("/", "\\") - path = lib_path.join(path).to_s.gsub("/", "\\") + mod_path = Vagrant::Util::Platform.wsl_to_windows_path(lib_path.join("utils")).gsub("/", "\\") + path = Vagrant::Util::Platform.wsl_to_windows_path(lib_path.join(path)).gsub("/", "\\") options = options || {} ps_options = [] options.each do |key, value| @@ -239,8 +239,9 @@ module VagrantPlugins # Include our module path so we can nicely load helper modules opts = { notify: [:stdout, :stderr, :stdin], - env: {"PSModulePath" => "$env:PSModulePath+';#{mod_path}'"} + module_path: Vagrant::Util::Platform.wsl_to_windows_path(mod_path) } + Vagrant::Util::PowerShell.execute(path, *ps_options, **opts, &block) end end