Skip to content

Commit bc04d4a

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/go: log more information about leaked temp files
Previously, we were only logging the top-level names of leaked directories, which doesn't provide much information for debugging. For #55260. Change-Id: I845d158135d67b5d7fdeb16ab7031a061535e643 Reviewed-on: https://go-review.googlesource.com/c/go/+/479055 Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 308ca75 commit bc04d4a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Diff for: src/cmd/go/go_test.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,33 @@ func TestMain(m *testing.M) {
312312

313313
if !*testWork {
314314
// There shouldn't be anything left in topTmpdir.
315-
dirf, err := os.Open(topTmpdir)
316-
if err != nil {
317-
log.Fatal(err)
318-
}
319-
names, err := dirf.Readdirnames(0)
315+
var extraFiles, extraDirs []string
316+
err := filepath.WalkDir(topTmpdir, func(path string, d fs.DirEntry, err error) error {
317+
if err != nil {
318+
return err
319+
}
320+
if path == topTmpdir {
321+
return nil
322+
}
323+
324+
if rel, err := filepath.Rel(topTmpdir, path); err == nil {
325+
path = rel
326+
}
327+
if d.IsDir() {
328+
extraDirs = append(extraDirs, path)
329+
} else {
330+
extraFiles = append(extraFiles, path)
331+
}
332+
return nil
333+
})
320334
if err != nil {
321335
log.Fatal(err)
322336
}
323-
if len(names) > 0 {
324-
log.Fatalf("unexpected files left in tmpdir: %v", names)
337+
338+
if len(extraFiles) > 0 {
339+
log.Fatalf("unexpected files left in tmpdir: %q", extraFiles)
340+
} else if len(extraDirs) > 0 {
341+
log.Fatalf("unexpected subdirectories left in tmpdir: %q", extraDirs)
325342
}
326343

327344
removeAll(topTmpdir)

0 commit comments

Comments
 (0)