Skip to content

Feature/eirikb/windows bootstrap fixes - #304

Merged
eirikb merged 2 commits into
mainfrom
feature/eirikb/windows-bootstrap-fixes
Jul 28, 2026
Merged

Feature/eirikb/windows bootstrap fixes#304
eirikb merged 2 commits into
mainfrom
feature/eirikb/windows-bootstrap-fixes

Conversation

@eirikb

@eirikb eirikb commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Both failures only hit the very first run, since stage1 short-circuits to the cached stage2 afterwards, and both come from the bootstrap inheriting a hostile environment: git bash and pwsh run gg.cmd through cmd.exe, so the batch branch executes with the parent shell's PATH and PSModulePath.

stage2.ps1: Get-FileHash lives in a script module, and PowerShell 7 prepends its Core-only copy of Microsoft.PowerShell.Utility to PSModulePath. A child Windows PowerShell then loads that one, keeps the binary cmdlets from the snap-in, and loses the script functions - so Invoke-WebRequest works while Get-FileHash is "not recognized". Hash through .NET instead, which needs no module loading.

stage1.bat: bare tar resolves to Git's GNU tar ahead of System32, which shells out to a separate gzip and reads "C:" as a remote host spec. Pin Windows' own bsdtar. A failed unpack also fell through to powershell -file on a stage2.ps1 that was never written, so the real error was buried under a confusing one - check the exit code and that stage2 actually landed.

Verified on Windows Server 2022 with cold caches: cmd, pwsh 7, git bash and 32-bit cmd with GNU tar first on PATH all bootstrap, and an unwritable cache dir now reports the unpack failure instead of the PowerShell -file error.

eirikb added 2 commits July 28, 2026 10:49
Both failures only hit the very first run, since stage1 short-circuits to the
cached stage2 afterwards, and both come from the bootstrap inheriting a hostile
environment: git bash and pwsh run gg.cmd through cmd.exe, so the batch branch
executes with the parent shell's PATH and PSModulePath.

stage2.ps1: Get-FileHash lives in a script module, and PowerShell 7 prepends its
Core-only copy of Microsoft.PowerShell.Utility to PSModulePath. A child Windows
PowerShell then loads that one, keeps the binary cmdlets from the snap-in, and
loses the script functions - so Invoke-WebRequest works while Get-FileHash is
"not recognized". Hash through .NET instead, which needs no module loading.

stage1.bat: bare tar resolves to Git's GNU tar ahead of System32, which shells
out to a separate gzip and reads "C:" as a remote host spec. Pin Windows' own
bsdtar. A failed unpack also fell through to powershell -file on a stage2.ps1
that was never written, so the real error was buried under a confusing one -
check the exit code and that stage2 actually landed.

Verified on Windows Server 2022 with cold caches: cmd, pwsh 7, git bash and
32-bit cmd with GNU tar first on PATH all bootstrap, and an unwritable cache
dir now reports the unpack failure instead of the PowerShell -file error.
stage1 is what you see when you cat gg.cmd, and every byte ships in it, so the
last commit was far too fat there: 1631 -> 2591 bytes for two real fixes.

The Sysnative probe goes - SysWOW64 has its own bsdtar, so a 32-bit cmd already
resolved a working tar through the plain System32 check and the extra line never
did anything. The exit-code guard goes too: we only get here when stage2.ps1 was
missing, so checking that it exists afterwards says the same thing in one test
and drops GG_UNTAR_ERR with it. Comments cut to the one trap worth naming, since
the reasoning lives in the commit log rather than in every copy of gg.cmd.

Down to 1945 bytes, +314 over the original instead of +960. Re-verified on
Windows Server 2022 with cold caches: cmd, pwsh 7, git bash, and 32-bit cmd with
GNU tar first on PATH, plus an unwritable cache dir still reporting the failure.
@eirikb
eirikb enabled auto-merge (squash) July 28, 2026 09:47
@eirikb
eirikb merged commit 931fecf into main Jul 28, 2026
177 checks passed
@eirikb
eirikb deleted the feature/eirikb/windows-bootstrap-fixes branch July 28, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant