]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: remove two erroneous uses of os.Stat
authorRuss Cox <rsc@golang.org>
Thu, 29 Oct 2020 18:54:47 +0000 (14:54 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 29 Oct 2020 20:55:24 +0000 (20:55 +0000)
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>
src/go/build/build.go

index 80e9b9c739d6cd733a1050bce2f14f56e0720349..82e481bdc212f85f50939e68900fcc083fb36ddd 100644 (file)
@@ -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) {