]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/testdir: remove temp files
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 5 Sep 2024 05:40:31 +0000 (22:40 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 6 Sep 2024 13:27:07 +0000 (13:27 +0000)
Function stdlibImportcfgFile creates a temporary directory and a file in
it, which are never deleted.

The easiest to fix this (without creating the file unnecessarily, or
creating it multiple times) is to add a global tmpDir and use it in
stdlibImportcfgFile.

Change-Id: Ia971b4478d9e0fa7c3a9b4c66e13fd5a4af9cbaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/610818
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/internal/testdir/testdir_test.go

index c3cadd5fc6a69fbf25b0d6d105cc857e604d68ff..1b78e605c840c260e73e5426350bdc3809f2863b 100644 (file)
@@ -63,6 +63,7 @@ var (
        cgoEnabled   bool
        goExperiment string
        goDebug      string
+       tmpDir       string
 
        // dirs are the directories to look for *.go files in.
        // TODO(bradfitz): just use all directories?
@@ -115,6 +116,7 @@ func Test(t *testing.T) {
        cgoEnabled, _ = strconv.ParseBool(env.CGO_ENABLED)
        goExperiment = env.GOEXPERIMENT
        goDebug = env.GODEBUG
+       tmpDir = t.TempDir()
 
        common := testCommon{
                gorootTestDir: filepath.Join(testenv.GOROOT(t), "test"),
@@ -220,12 +222,8 @@ var stdlibImportcfg = sync.OnceValue(func() string {
 })
 
 var stdlibImportcfgFile = sync.OnceValue(func() string {
-       tmpdir, err := os.MkdirTemp("", "importcfg")
-       if err != nil {
-               log.Fatal(err)
-       }
-       filename := filepath.Join(tmpdir, "importcfg")
-       err = os.WriteFile(filename, []byte(stdlibImportcfg()), 0644)
+       filename := filepath.Join(tmpDir, "importcfg")
+       err := os.WriteFile(filename, []byte(stdlibImportcfg()), 0644)
        if err != nil {
                log.Fatal(err)
        }