From 9a1596689e7700dad70270325542898bd2afcd7d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 29 Oct 2020 14:54:47 -0400 Subject: [PATCH] go/build: remove two erroneous uses of os.Stat go/build should use the ctxt routines, not os directly. These snuck in. Change-Id: I918d4de923eb485bfd524e4f1b1310a7a165ad03 Reviewed-on: https://go-review.googlesource.com/c/go/+/266357 Trust: Russ Cox Trust: Jay Conrod Run-TryBot: Russ Cox Reviewed-by: Jay Conrod --- src/go/build/build.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/go/build/build.go b/src/go/build/build.go index 80e9b9c739d..82e481bdc21 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -805,7 +805,7 @@ Found: continue } if d.Mode()&fs.ModeSymlink != 0 { - if fi, err := os.Stat(filepath.Join(p.Dir, d.Name())); err == nil && fi.IsDir() { + if ctxt.isDir(ctxt.joinPath(p.Dir, d.Name())) { // Symlinks to directories are not source files. continue } @@ -1117,9 +1117,14 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode) } } for { - info, err := os.Stat(filepath.Join(parent, "go.mod")) - if err == nil && !info.IsDir() { - break + if f, err := ctxt.openFile(ctxt.joinPath(parent, "go.mod")); err == nil { + buf := make([]byte, 100) + _, err := f.Read(buf) + f.Close() + if err == nil || err == io.EOF { + // go.mod exists and is readable (is a file, not a directory). + break + } } d := filepath.Dir(parent) if len(d) >= len(parent) {