Capture-MclCache: after a failed robocopy, still check and name the files that did not arrive
This commit is contained in:
@@ -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
|
||||
$rc = $LASTEXITCODE
|
||||
if ($rc -ge 8) {
|
||||
Write-Host "Copy FAILED (robocopy exit $rc)." -ForegroundColor Red
|
||||
exit 2
|
||||
# Keep going: the check below names the files that did not arrive.
|
||||
Write-Host "robocopy could not copy some files (exit $rc)." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Read every file back through the share and compare with SHA256SUMS.
|
||||
@@ -200,16 +200,20 @@ foreach ($line in $sumLines) {
|
||||
$rel = $line.Substring(66)
|
||||
$copy = Join-Path $target ($rel.Replace('/', '\'))
|
||||
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 ((Get-FileHash -LiteralPath (Join-Path $target "SHA256SUMS") -Algorithm SHA256).Hash -ne
|
||||
(Get-FileHash -LiteralPath (Join-Path $dest "SHA256SUMS") -Algorithm SHA256).Hash) {
|
||||
$bad.Add("differs SHA256SUMS")
|
||||
}
|
||||
try {
|
||||
if ((Get-FileHash -LiteralPath (Join-Path $target "SHA256SUMS") -Algorithm SHA256).Hash -ne
|
||||
(Get-FileHash -LiteralPath (Join-Path $dest "SHA256SUMS") -Algorithm SHA256).Hash) {
|
||||
$bad.Add("differs SHA256SUMS")
|
||||
}
|
||||
} catch { $bad.Add("unreadable SHA256SUMS") }
|
||||
if ($bad.Count) {
|
||||
Write-Host "Copy NOT verified: $($bad.Count) of $($sumLines.Count + 1) files wrong." -ForegroundColor Red
|
||||
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
|
||||
}
|
||||
Write-Host "Copied and verified: all $($sumLines.Count + 1) files match." -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user