From 2b9e913458cf896cad1eba6a47f9cf035181150f Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Wed, 20 Jan 2016 12:26:20 +1100 Subject: [PATCH] Remove unnecessary logic from Context.matchPackages Updates #505 The fix for #505 in #555 was overly agressive, remove the unnecessary parts. --- context.go | 72 +++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/context.go b/context.go index aa01727..55419fc 100644 --- a/context.go +++ b/context.go @@ -441,50 +441,40 @@ func matchPackages(c *Context, pattern string) ([]string, error) { var pkgs []string - srcs := []string{ - filepath.Join(c.Projectdir(), "src") + string(filepath.Separator), - filepath.Join(c.Projectdir(), "vendor", "src") + string(filepath.Separator), - } - for _, src := range srcs { - err := filepath.Walk(src, func(path string, fi os.FileInfo, err error) error { - if err != nil || !fi.IsDir() || path == src { - return nil - } + src := filepath.Join(c.Projectdir(), "src") + string(filepath.Separator) + err := filepath.Walk(src, func(path string, fi os.FileInfo, err error) error { + if err != nil || !fi.IsDir() || path == src { + return nil + } - // Avoid .foo, _foo, and testdata directory trees. - elem := fi.Name() - if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" { - return filepath.SkipDir - } + // Avoid .foo, _foo, and testdata directory trees. + elem := fi.Name() + if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" { + return filepath.SkipDir + } - name := filepath.ToSlash(path[len(src):]) - if pattern == "std" && strings.Contains(name, ".") { - return filepath.SkipDir - } - if !treeCanMatch(name) { - return filepath.SkipDir - } - if !match(name) { - return nil - } - _, err = c.importers[1].Import(name) - switch err.(type) { - case nil: - pkgs = append(pkgs, name) - return nil - case *importer.NoGoError: - return nil // skip - case *os.PathError: - return nil // skip - default: - return err - } - }) - if err != nil { - return nil, err + name := filepath.ToSlash(path[len(src):]) + if pattern == "std" && strings.Contains(name, ".") { + return filepath.SkipDir } - } - return pkgs, nil + if !treeCanMatch(name) { + return filepath.SkipDir + } + if !match(name) { + return nil + } + _, err = c.importers[1].Import(name) + switch err.(type) { + case nil: + pkgs = append(pkgs, name) + return nil + case *importer.NoGoError: + return nil // skip + default: + return err + } + }) + return pkgs, err } // envForDir returns a copy of the environment