Skip to content

Commit

Permalink
cmd/go: replace some more stats with fsys.Stat
Browse files Browse the repository at this point in the history
To support overlays

For #39958

Change-Id: I5ffd72aeb7f5f30f6c60f6334a01a0a1383c7945
Reviewed-on: https://go-review.googlesource.com/c/go/+/264478
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
  • Loading branch information
matloob committed Oct 23, 2020
1 parent c3fe874 commit 3931cc1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/cmd/go/internal/imports/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package imports
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strconv"
Expand All @@ -28,7 +27,7 @@ func ScanDir(dir string, tags map[string]bool) ([]string, []string, error) {
// If the directory entry is a symlink, stat it to obtain the info for the
// link target instead of the link itself.
if info.Mode()&fs.ModeSymlink != 0 {
info, err = os.Stat(filepath.Join(dir, name))
info, err = fsys.Stat(filepath.Join(dir, name))
if err != nil {
continue // Ignore broken symlinks.
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/go/internal/modload/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import (

"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/fsys"
"cmd/go/internal/imports"
"cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
Expand Down Expand Up @@ -361,7 +362,7 @@ func resolveLocalPackage(dir string) (string, error) {
// If the named directory does not exist or contains no Go files,
// the package does not exist.
// Other errors may affect package loading, but not resolution.
if _, err := os.Stat(absDir); err != nil {
if _, err := fsys.Stat(absDir); err != nil {
if os.IsNotExist(err) {
// Canonicalize OS-specific errors to errDirectoryNotFound so that error
// messages will be easier for users to search for.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modload/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f

if !fi.IsDir() {
if fi.Mode()&fs.ModeSymlink != 0 && want {
if target, err := os.Stat(path); err == nil && target.IsDir() {
if target, err := fsys.Stat(path); err == nil && target.IsDir() {
fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (m *Match) MatchPackages() {

if !fi.IsDir() {
if fi.Mode()&fs.ModeSymlink != 0 && want {
if target, err := os.Stat(path); err == nil && target.IsDir() {
if target, err := fsys.Stat(path); err == nil && target.IsDir() {
fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
}
}
Expand Down

0 comments on commit 3931cc1

Please sign in to comment.