Execute web requests only once

This commit is contained in:
Manuel Thalmann 2023-07-15 12:24:04 +02:00
parent 60d9691f45
commit de58359af4

View file

@ -6,12 +6,13 @@ function Install-SoftwarePackage([Context] $context, [string] $location, [string
if (-not ($local.IsPresent)) {
$tempDir = $context.GetTempDirectory();
$tempFile = Join-Path $tempDir "download.tmp";
$response = Invoke-WebRequest $location;
$response = Invoke-WebRequest $location -OutFile $tempFile;
$fileName = [System.IO.Path]::GetFileName($response.Headers["Location"]);
$filePath = Join-Path $tempDir $fileName;
Invoke-WebRequest $location $filePath;
Move-Item $tempFile $filePath;
} else {
$filePath = $location;
}