Skip to content

Commit

Permalink
cmd/internal/testdir: remove temp files
Browse files Browse the repository at this point in the history
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 <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
kolyshkin authored and gopherbot committed Sep 6, 2024
1 parent 2b832b4 commit ca2cb8d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/cmd/internal/testdir/testdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit ca2cb8d

Please sign in to comment.