aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/search/search.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-05-06 16:22:15 -0400
committerBryan C. Mills <bcmills@google.com>2020-05-13 18:51:10 +0000
commit14bec27743365511495eadb2accf76efaccbc525 (patch)
tree5af6e61b7e5e5633750688e6869b16aeff19ff1f /src/cmd/go/internal/search/search.go
parentb819adfe6d3bb53b1c863d5c5a8b64b89698d9f7 (diff)
downloadgo-14bec27743365511495eadb2accf76efaccbc525.tar.gz
go-14bec27743365511495eadb2accf76efaccbc525.zip
cmd/go: do not ignore permission errors when matching patterns
While reviewing CL 228784, I noticed that various filepath.WalkFunc implementations within cmd/go were dropping non-nil errors. Those errors turn out to be significant, at least in some cases: for example, they can cause packages to appear to be missing when any parent of the directory had the wrong permissions set. (This also turned up a bug in the existing list_dedup_packages test, which was accidentally passing a nonexistent directory instead of the intended duplicate path.) Change-Id: Ia09a0a33aa7a966d9f132d3747d6c674a5370b2d Reviewed-on: https://go-review.googlesource.com/c/go/+/232579 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/search/search.go')
-rw-r--r--src/cmd/go/internal/search/search.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go
index b588c3e467..4efef24152 100644
--- a/src/cmd/go/internal/search/search.go
+++ b/src/cmd/go/internal/search/search.go
@@ -128,8 +128,11 @@ func (m *Match) MatchPackages() {
root += "cmd" + string(filepath.Separator)
}
err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
- if err != nil || path == src {
- return nil
+ if err != nil {
+ return err // Likely a permission error, which could interfere with matching.
+ }
+ if path == src {
+ return nil // GOROOT/src and GOPATH/src cannot contain packages.
}
want := true
@@ -261,7 +264,10 @@ func (m *Match) MatchDirs() {
}
err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
- if err != nil || !fi.IsDir() {
+ if err != nil {
+ return err // Likely a permission error, which could interfere with matching.
+ }
+ if !fi.IsDir() {
return nil
}
top := false