Skip to content

Commit

Permalink
Don't try to parse directories named *.go
Browse files Browse the repository at this point in the history
fillPackage is supposed to use the AST parser on individual files.
Unforntunately, `filepath.Glob("*.go")` returns directories as well as
files.

Fixes golang#550
  • Loading branch information
ascandella committed May 10, 2017
1 parent 1ecd916 commit 536add9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Empty file.
6 changes: 6 additions & 0 deletions internal/gps/pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ func fillPackage(p *build.Package) error {
if filepath.Base(file)[0] == '_' {
continue
}

// Skip any directories that happen to end with ".go"
if stat, err := os.Stat(file); err == nil && stat.IsDir() {
continue
}

pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments)
if err != nil {
if os.IsPermission(err) {
Expand Down
5 changes: 5 additions & 0 deletions internal/gps/pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,11 @@ func TestListPackages(t *testing.T) {
},
},
},
"skip '.go' directories": {
fileRoot: j("dotgodir"),
importRoot: "dotgodir",
err: nil,
},
}

for name, fix := range table {
Expand Down

0 comments on commit 536add9

Please sign in to comment.