Prevent unnecessary errors during WSL execution

This commit is contained in:
Manuel Thalmann 2024-08-21 14:08:26 +02:00
parent 23d25111ea
commit 8812b00b2e

View file

@ -30,33 +30,36 @@ $null = New-Module {
[string] $Path [string] $Path
) )
$completed = $false; & {
$ErrorActionPreference = 'Continue';
$completed = $false;
while (-not $completed) { while (-not $completed) {
$job = Start-Job { $job = Start-Job {
$env:Value = Resolve-Path $Using:Path; $env:Value = Resolve-Path $Using:Path;
$env:WSLENV = "Value/p"; $env:WSLENV = "Value/p";
$result = wsl -- bash -c 'echo "$Value"'; $result = wsl -- bash -c 'echo "$Value"';
wsl -e printf "%q" "$result"; 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``";
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;
}
$result = Receive-Job -Wait $job; $completed = $true;
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;
} };
$result;
} }
<# <#