import (
"context"
+ "errors"
"fmt"
"io"
+ "io/fs"
"os"
"path/filepath"
"runtime"
if !cfg.BuildN {
if err := modfetch.RemoveAll(cfg.GOMODCACHE); err != nil {
base.Error(err)
+
+ // Add extra logging for the purposes of debugging #68087.
+ // We're getting ENOTEMPTY errors on openbsd from RemoveAll.
+ // Check for os.ErrExist, which can match syscall.ENOTEMPTY
+ // and syscall.EEXIST, because syscall.ENOTEMPTY is not defined
+ // on all platforms.
+ if runtime.GOOS == "openbsd" && errors.Is(err, fs.ErrExist) {
+ logFilesInGOMODCACHE()
+ }
}
}
}
}
}
+// logFilesInGOMODCACHE reports the file names and modes for the files in GOMODCACHE using base.Error.
+func logFilesInGOMODCACHE() {
+ var found []string
+ werr := filepath.WalkDir(cfg.GOMODCACHE, func(path string, d fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ var mode string
+ info, err := d.Info()
+ if err == nil {
+ mode = info.Mode().String()
+ } else {
+ mode = fmt.Sprintf("<err: %s>", info.Mode())
+ }
+ found = append(found, fmt.Sprintf("%s (mode: %s)", path, mode))
+ return nil
+ })
+ if werr != nil {
+ base.Errorf("walking files in GOMODCACHE (for debugging go.dev/issue/68087): %v", werr)
+ }
+ base.Errorf("files in GOMODCACHE (for debugging go.dev/issue/68087):\n%s", strings.Join(found, "\n"))
+}
+
var cleaned = map[*load.Package]bool{}
// TODO: These are dregs left by Makefile-based builds.