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 <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Bryan C. Mills 2023-03-23 16:10:52 -04:00 committed by Gopher Robot
parent 308ca75edb
commit bc04d4afa2
1 changed files with 24 additions and 7 deletions

View File

@ -312,16 +312,33 @@ func TestMain(m *testing.M) {
if !*testWork {
// There shouldn't be anything left in topTmpdir.
dirf, err := os.Open(topTmpdir)
var extraFiles, extraDirs []string
err := filepath.WalkDir(topTmpdir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if path == topTmpdir {
return nil
}
if rel, err := filepath.Rel(topTmpdir, path); err == nil {
path = rel
}
if d.IsDir() {
extraDirs = append(extraDirs, path)
} else {
extraFiles = append(extraFiles, path)
}
return nil
})
if err != nil {
log.Fatal(err)
}
names, err := dirf.Readdirnames(0)
if err != nil {
log.Fatal(err)
}
if len(names) > 0 {
log.Fatalf("unexpected files left in tmpdir: %v", names)
if len(extraFiles) > 0 {
log.Fatalf("unexpected files left in tmpdir: %q", extraFiles)
} else if len(extraDirs) > 0 {
log.Fatalf("unexpected subdirectories left in tmpdir: %q", extraDirs)
}
removeAll(topTmpdir)