From: Russ Cox Date: Thu, 29 Oct 2020 18:54:47 +0000 (-0400) Subject: go/build: remove two erroneous uses of os.Stat X-Git-Tag: go1.16beta1~409 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9a1596689e7700dad70270325542898bd2afcd7d;p=gostls13.git 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 --- diff --git a/src/go/build/build.go b/src/go/build/build.go index 80e9b9c739..82e481bdc2 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) {