From 1e8a06cd88531a1c6861e080f4b96adcdebb8040 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 20 Aug 2024 00:20:33 +0200 Subject: [PATCH] Retry Linux path conversion for errors --- scripts/Common/Scripts/Config.ps1 | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 34f56f1f..f846506b 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -30,21 +30,30 @@ $null = New-Module { [string] $Path ) - $job = Start-Job { - $env:Value = Resolve-Path $Using:Path; - $env:WSLENV = "Value/p"; - $result = wsl -- bash -c 'echo "$Value"'; - wsl -e printf "%q" "$result"; - }; + $completed = $false; - $result = Receive-Job -Wait $job; + while (-not $completed) { + $job = Start-Job { + $env:Value = Resolve-Path $Using:Path; + $env:WSLENV = "Value/p"; + $result = wsl -- bash -c 'echo "$Value"'; + wsl -e printf "%q" "$result"; + }; + + $result = Receive-Job -Wait $job; - if ((Split-Path -Leaf $Path) -ne (Split-Path -Leaf $result)) { - Write-Error "The result of the path conversion of ``$Path`` was unexpected: ``$result``"; - } - if ($job.State -ne ([System.Management.Automation.JobState]::Completed)) { - Write-Error "An error occurred while converting ``$Path`` to a Linux path.`nOutput: ``$result``"; + if ((Split-Path -Leaf $Path) -ne (Split-Path -Leaf $result)) { + Write-Error "The result of the path conversion of ``$Path`` was unexpected: ``$result``"; + continue; + } + + if ($job.State -ne ([System.Management.Automation.JobState]::Completed)) { + Write-Error "An error occurred while converting ``$Path`` to a Linux path.`nOutput: ``$result``"; + continue; + } + + $completed = $true; } $result;