Don't pass synthesized TMPDIR if not already set (#409)

## Changes

On Unix systems, the default of `/tmp` always works. No need to
synthesize a path for it.

The custom TMPDIR was causing issues when used from GitHub Actions
runners.

## Tests

Confirmed manually this fixes the issue on GitHub Actions runners.
This commit is contained in:
Pieter Noordhuis 2023-05-26 11:05:30 +00:00 committed by GitHub
parent 854444077f
commit e4ab455ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 13 deletions

View File

@ -95,14 +95,9 @@ func setTempDirEnvVars(env map[string]string, b *bundle.Bundle) error {
env["TMP"] = tmpDir env["TMP"] = tmpDir
} }
default: default:
// If TMPDIR is not set, we let the process fall back to its default value.
if v, ok := os.LookupEnv("TMPDIR"); ok { if v, ok := os.LookupEnv("TMPDIR"); ok {
env["TMPDIR"] = v env["TMPDIR"] = v
} else {
tmpDir, err := b.CacheDir("tmp")
if err != nil {
return err
}
env["TMPDIR"] = tmpDir
} }
} }
return nil return nil

View File

@ -69,7 +69,7 @@ func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) {
err := setTempDirEnvVars(env, b) err := setTempDirEnvVars(env, b)
require.NoError(t, err) require.NoError(t, err)
// assert that we pass through env var value // Assert that we pass through TMPDIR.
assert.Equal(t, map[string]string{ assert.Equal(t, map[string]string{
"TMPDIR": "/foo/bar", "TMPDIR": "/foo/bar",
}, env) }, env)
@ -97,12 +97,8 @@ func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) {
err := setTempDirEnvVars(env, b) err := setTempDirEnvVars(env, b)
require.NoError(t, err) require.NoError(t, err)
// assert tmp dir is set to b.CacheDir("tmp") // Assert that we don't pass through TMPDIR.
tmpDir, err := b.CacheDir("tmp") assert.Equal(t, map[string]string{}, env)
require.NoError(t, err)
assert.Equal(t, map[string]string{
"TMPDIR": tmpDir,
}, env)
} }
func TestSetTempDirEnvVarsForWindowWithAllTmpDirEnvVarsSet(t *testing.T) { func TestSetTempDirEnvVarsForWindowWithAllTmpDirEnvVarsSet(t *testing.T) {