mirror of
https://github.com/hansjone/netx.git
synced 2026-10-15 22:20:46 +08:00
Retry interrupted PostgreSQL release downloads
This commit is contained in:
parent
19d4597b94
commit
06d2df1b1f
1 changed files with 26 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ $url = "https://get.enterprisedb.com/postgresql/postgresql-$ver-windows-x64-bina
|
||||||
|
|
||||||
$cache = if ($OutDir) { $OutDir } else { Join-Path $PSScriptRoot "cache" }
|
$cache = if ($OutDir) { $OutDir } else { Join-Path $PSScriptRoot "cache" }
|
||||||
$zipPath = Join-Path $cache "postgresql-$ver-windows-x64-binaries.zip"
|
$zipPath = Join-Path $cache "postgresql-$ver-windows-x64-binaries.zip"
|
||||||
|
$partialPath = "$zipPath.partial"
|
||||||
$extractRoot = Join-Path $cache "pgsql-$ver"
|
$extractRoot = Join-Path $cache "pgsql-$ver"
|
||||||
$destPgsql = Join-Path $PSScriptRoot "postgres\pgsql"
|
$destPgsql = Join-Path $PSScriptRoot "postgres\pgsql"
|
||||||
|
|
||||||
|
|
@ -22,7 +23,31 @@ if (-not (Test-Path $cache)) {
|
||||||
Write-Host "==> PostgreSQL binaries URL: $url"
|
Write-Host "==> PostgreSQL binaries URL: $url"
|
||||||
if (-not (Test-Path $zipPath)) {
|
if (-not (Test-Path $zipPath)) {
|
||||||
Write-Host "==> Downloading (large; may take several minutes)..."
|
Write-Host "==> Downloading (large; may take several minutes)..."
|
||||||
Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing
|
$curl = Get-Command curl.exe -ErrorAction SilentlyContinue
|
||||||
|
if ($curl) {
|
||||||
|
# PostgreSQL's archive is several hundred MB. Resume interrupted transfers
|
||||||
|
# instead of restarting the entire download when the CDN drops a connection.
|
||||||
|
& $curl.Source --fail --location --retry 8 --retry-all-errors --retry-delay 3 `
|
||||||
|
--connect-timeout 30 --continue-at - --output $partialPath $url
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "postgres_download_failed: curl exit $LASTEXITCODE (partial file kept at $partialPath)"
|
||||||
|
}
|
||||||
|
Move-Item -LiteralPath $partialPath -Destination $zipPath -Force
|
||||||
|
} else {
|
||||||
|
# Fallback for environments without curl; retry from scratch on transient errors.
|
||||||
|
$downloaded = $false
|
||||||
|
for ($attempt = 1; $attempt -le 3 -and -not $downloaded; $attempt++) {
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri $url -OutFile $partialPath -UseBasicParsing
|
||||||
|
Move-Item -LiteralPath $partialPath -Destination $zipPath -Force
|
||||||
|
$downloaded = $true
|
||||||
|
} catch {
|
||||||
|
if ($attempt -eq 3) { throw }
|
||||||
|
Remove-Item -LiteralPath $partialPath -Force -ErrorAction SilentlyContinue
|
||||||
|
Start-Sleep -Seconds (5 * $attempt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "==> Using cached zip: $zipPath"
|
Write-Host "==> Using cached zip: $zipPath"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue