Capture-MclCache: after a failed robocopy, still check and name the files that did not arrive

This commit is contained in:
cproudlock
2026-10-18 09:44:18 -04:00
parent 716d4eee6b
commit 2dac8d384b

View File

@@ -189,8 +189,8 @@ Write-Host "Copying to $target ..."
& robocopy.exe $dest $target /E /COPY:DT /R:2 /W:5 /NP /NFL /NDL /NJH /NJS | Out-Null & robocopy.exe $dest $target /E /COPY:DT /R:2 /W:5 /NP /NFL /NDL /NJH /NJS | Out-Null
$rc = $LASTEXITCODE $rc = $LASTEXITCODE
if ($rc -ge 8) { if ($rc -ge 8) {
Write-Host "Copy FAILED (robocopy exit $rc)." -ForegroundColor Red # Keep going: the check below names the files that did not arrive.
exit 2 Write-Host "robocopy could not copy some files (exit $rc)." -ForegroundColor Yellow
} }
# Read every file back through the share and compare with SHA256SUMS. # Read every file back through the share and compare with SHA256SUMS.
@@ -200,16 +200,20 @@ foreach ($line in $sumLines) {
$rel = $line.Substring(66) $rel = $line.Substring(66)
$copy = Join-Path $target ($rel.Replace('/', '\')) $copy = Join-Path $target ($rel.Replace('/', '\'))
if (-not (Test-Path -LiteralPath $copy -PathType Leaf)) { $bad.Add("missing $rel"); continue } if (-not (Test-Path -LiteralPath $copy -PathType Leaf)) { $bad.Add("missing $rel"); continue }
$got = (Get-FileHash -LiteralPath $copy -Algorithm SHA256).Hash.ToLower() try { $got = (Get-FileHash -LiteralPath $copy -Algorithm SHA256).Hash.ToLower() }
catch { $bad.Add("unreadable $rel"); continue }
if ($got -ne $hash) { $bad.Add("differs $rel ($((Get-Item -LiteralPath $copy).Length) bytes)") } if ($got -ne $hash) { $bad.Add("differs $rel ($((Get-Item -LiteralPath $copy).Length) bytes)") }
} }
if ((Get-FileHash -LiteralPath (Join-Path $target "SHA256SUMS") -Algorithm SHA256).Hash -ne try {
(Get-FileHash -LiteralPath (Join-Path $dest "SHA256SUMS") -Algorithm SHA256).Hash) { if ((Get-FileHash -LiteralPath (Join-Path $target "SHA256SUMS") -Algorithm SHA256).Hash -ne
$bad.Add("differs SHA256SUMS") (Get-FileHash -LiteralPath (Join-Path $dest "SHA256SUMS") -Algorithm SHA256).Hash) {
} $bad.Add("differs SHA256SUMS")
}
} catch { $bad.Add("unreadable SHA256SUMS") }
if ($bad.Count) { if ($bad.Count) {
Write-Host "Copy NOT verified: $($bad.Count) of $($sumLines.Count + 1) files wrong." -ForegroundColor Red Write-Host "Copy NOT verified: $($bad.Count) of $($sumLines.Count + 1) files wrong." -ForegroundColor Red
foreach ($b in $bad) { Write-Host " $b" } foreach ($b in $bad) { Write-Host " $b" }
Write-Host "A file that arrives with 0 bytes was most likely blocked by this PC's policy."
exit 2 exit 2
} }
Write-Host "Copied and verified: all $($sumLines.Count + 1) files match." -ForegroundColor Green Write-Host "Copied and verified: all $($sumLines.Count + 1) files match." -ForegroundColor Green