Files
elysium/tools
tomas.kracmar a7f350230b fix(Prepare-KHDBStorage): actually write invalid-hashes.txt
The summary says "Invalid lines saved to .../invalid-hashes.txt" and
prints samples, but the file was always empty. $ensureInvalidWriter
is a scriptblock invoked with `&`, so it runs in a child scope:
`$invalidWriter = New-Object StreamWriter(...)` created a variable
local to that call, the outer $invalidWriter stayed $null, and every
`if ($invalidWriter) { ...WriteLine() }` was skipped. Same class of
bug as the $meta counter fixed in 06e7607.

Side effect: each invalid line opened another StreamWriter on the
same file (FileShare.Read) and never disposed it. macOS does not
enforce .NET share modes, so this only showed up as the empty file
here; on Windows the second open is expected to throw a sharing
violation and abort the publish once the input has two or more
invalid lines (not verified on Windows).

The writer now lives in a hashtable (`$invalidOutput.Writer`), which
the scriptblock mutates by reference; all 14 uses switched over.

Found by the new publish -> update round-trip test, included here:
tools/Prepare-KHDBStorage.ps1 -SkipUpload on 400 pre-sorted hashes
with mixed case, HASH:count suffixes, adjacent duplicates and a junk
line, then Update-ElysiumKhdb consumes the package. Asserts the junk
line lands in invalid-hashes.txt and the client rebuilds exactly the
sorted, unique, upper-case set. Before the fix: invalid-hashes.txt
empty (0 bytes with two junk lines). After: both lines written;
23/23 Pester tests pass.
2026-11-04 13:04:46 +01:00
..