Don't pass synthesized TMPDIR if not already set

This commit is contained in:
Pieter Noordhuis 2023-05-26 10:54:40 +02:00
parent d8f1e344a7
commit 533ef616fe
No known key found for this signature in database
GPG Key ID: 12ACCCC104CF2930
2 changed files with 6 additions and 14 deletions

View File

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

View File

@ -48,7 +48,7 @@ func TestInitEnvironmentVariables(t *testing.T) {
} }
func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) { func TestSetTempDirEnvVarsForUnixWithTmpDirSet(t *testing.T) {
if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") {
t.SkipNow() t.SkipNow()
} }
@ -69,14 +69,14 @@ 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)
} }
func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) { func TestSetTempDirEnvVarsForUnixWithTmpDirNotSet(t *testing.T) {
if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { if !(runtime.GOOS == "darwin" || runtime.GOOS == "linux") {
t.SkipNow() t.SkipNow()
} }
@ -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) {