Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Remove unnecessary logic from Context.matchPackages
Browse files Browse the repository at this point in the history
Updates #505

The fix for #505 in #555 was overly agressive, remove the unnecessary parts.
  • Loading branch information
davecheney committed Jan 20, 2016
1 parent bc1d3d5 commit 2b9e913
Showing 1 changed file with 31 additions and 41 deletions.
72 changes: 31 additions & 41 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b9e913

Please sign in to comment.