1
0
mirror of https://github.com/golang/go synced 2024-11-16 21:44:52 -07:00

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 <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Russ Cox 2020-10-29 14:54:47 -04:00
parent 09d5e0d119
commit 9a1596689e

View File

@ -805,7 +805,7 @@ Found:
continue continue
} }
if d.Mode()&fs.ModeSymlink != 0 { 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. // Symlinks to directories are not source files.
continue continue
} }
@ -1117,9 +1117,14 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
} }
} }
for { for {
info, err := os.Stat(filepath.Join(parent, "go.mod")) if f, err := ctxt.openFile(ctxt.joinPath(parent, "go.mod")); err == nil {
if err == nil && !info.IsDir() { buf := make([]byte, 100)
break _, 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) d := filepath.Dir(parent)
if len(d) >= len(parent) { if len(d) >= len(parent) {