restore-mmap: prefer local chunks/
This commit is contained in:
parent
b2ebad564e
commit
b29457b0d9
@ -1,36 +1,24 @@
|
||||
# Restores "nomad_27 copy.mmap" from Release mmap-current assets.
|
||||
# Restore nomad_27 copy.mmap from ./chunks or Release mmap-current
|
||||
$ErrorActionPreference = "Stop"
|
||||
$owner = "hackrobot"
|
||||
$repo = "newmindjet"
|
||||
$tag = "mmap-current"
|
||||
$outFile = Join-Path $PSScriptRoot "nomad_27 copy.mmap"
|
||||
$api = "https://git.nomadro.cn/api/v1/repos/$owner/$repo/releases/tags/$tag"
|
||||
|
||||
Write-Host "Fetching release $tag ..."
|
||||
$rel = Invoke-RestMethod -Uri $api -Method Get
|
||||
$assets = $rel.assets | Sort-Object name
|
||||
if (-not $assets -or $assets.Count -eq 0) { throw "No assets found on release $tag" }
|
||||
|
||||
$chunkDir = Join-Path $PSScriptRoot "chunks"
|
||||
function Join-Parts($parts, $outFile) {
|
||||
if (Test-Path $outFile) { Remove-Item $outFile -Force }
|
||||
$fs = [IO.File]::Create($outFile)
|
||||
try { foreach ($p in $parts) { $b=[IO.File]::ReadAllBytes($p.FullName); $fs.Write($b,0,$b.Length) } }
|
||||
finally { $fs.Close() }
|
||||
Write-Host "Wrote $outFile ($((Get-Item $outFile).Length) bytes)"
|
||||
}
|
||||
if (Test-Path $chunkDir) {
|
||||
$parts = Get-ChildItem $chunkDir -File -Filter "part.*" | Sort-Object Name
|
||||
if ($parts.Count -gt 0) { Write-Host "Joining $($parts.Count) local chunks ..."; Join-Parts $parts $outFile; exit 0 }
|
||||
}
|
||||
Write-Host "No local chunks; downloading Release mmap-current ..."
|
||||
$api = "https://git.nomadro.cn/api/v1/repos/hackrobot/newmindjet/releases/tags/mmap-current"
|
||||
$rel = Invoke-RestMethod -Uri $api
|
||||
$tmp = Join-Path $env:TEMP ("mmap-restore-" + [guid]::NewGuid().ToString("n"))
|
||||
New-Item -ItemType Directory -Path $tmp | Out-Null
|
||||
try {
|
||||
$i = 0
|
||||
foreach ($a in $assets) {
|
||||
$i++
|
||||
$dest = Join-Path $tmp $a.name
|
||||
Write-Host "[$i/$($assets.Count)] $($a.name) ($($a.size) bytes)"
|
||||
Invoke-WebRequest -Uri $a.browser_download_url -OutFile $dest -UseBasicParsing
|
||||
}
|
||||
if (Test-Path $outFile) { Remove-Item $outFile -Force }
|
||||
$parts = Get-ChildItem $tmp -File | Sort-Object Name
|
||||
$fs = [IO.File]::Create($outFile)
|
||||
try {
|
||||
foreach ($p in $parts) {
|
||||
$bytes = [IO.File]::ReadAllBytes($p.FullName)
|
||||
$fs.Write($bytes, 0, $bytes.Length)
|
||||
}
|
||||
} finally { $fs.Close() }
|
||||
Write-Host "Wrote $outFile ($((Get-Item $outFile).Length) bytes)"
|
||||
} finally {
|
||||
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
$n=0; foreach ($a in ($rel.assets | Sort-Object name)) { $n++; Write-Host "[$n/$($rel.assets.Count)] $($a.name)"; Invoke-WebRequest -Uri $a.browser_download_url -OutFile (Join-Path $tmp $a.name) -UseBasicParsing }
|
||||
Join-Parts (Get-ChildItem $tmp -File | Sort-Object Name) $outFile
|
||||
} finally { Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user