do not create ./build in cwd when cache init is skipped (#1035)

sharedCache is allocated before goVersionOK runs, but CacheDir is
only set once the version check passes. The trim defer in mainErr
only checked sharedCache != nil, so on the too-new-version path
openCache joined an empty CacheDir with "build" and created the
directory in CWD.

Fixes #995.
This commit is contained in:
KismetDev
2026-04-21 18:00:42 +02:00
committed by GitHub
parent eef2eae50b
commit 900696b816
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ func mainErr(args []string) error {
fmt.Fprintf(os.Stderr, "could not clean up GARBLE_SHARED: %v\n", err)
}
// skip the trim if we didn't even start a build
if sharedCache != nil {
if sharedCache != nil && sharedCache.CacheDir != "" {
fsCache, err := openCache()
if err == nil {
err = fsCache.Trim()
+2
View File
@@ -39,6 +39,8 @@ env GARBLE_TEST_GOVERSION='go1.38.2'
env TOOLCHAIN_GOVERSION='go1.38.2'
! exec garble build
stderr 'Go version "go1\.38\.2" is too new; Go linker patches aren''t available for go1\.27 or later yet'
# Ensure we don't create a cache directory in the current dir.
! exists build
# We should accept custom devel strings.
env TOOLCHAIN_GOVERSION='go1.26.0-somecustomversion'