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

gps.ListPackages fails when project contains a directory named ".go" #550

Closed
ascandella opened this issue May 10, 2017 · 0 comments · Fixed by #551
Closed

gps.ListPackages fails when project contains a directory named ".go" #550

ascandella opened this issue May 10, 2017 · 0 comments · Fixed by #551

Comments

@ascandella
Copy link
Contributor

ascandella commented May 10, 2017

Repro case:

example-dep-ensure ❯ ls -fl
total 0
drwxr-xr-x  3 aiden  staff  102 May 10 14:18 .
drwxr-xr-x  9 aiden  staff  306 May 10 14:17 ..
drwxr-xr-x  2 aiden  staff   68 May 10 14:16 .go
example-dep-ensure ❯ dep init
gps.ListPackages: read /Users/aiden/src/go/src/github.com/sectioneight/example-dep-ensure/.go: is a directory

Proposed fix:

diff --git c/internal/gps/pkgtree/pkgtree.go i/internal/gps/pkgtree/pkgtree.go
index a83fb4e..cf6346c 100644
--- c/internal/gps/pkgtree/pkgtree.go
+++ i/internal/gps/pkgtree/pkgtree.go
@@ -203,6 +203,12 @@ func fillPackage(p *build.Package) error {
 		if filepath.Base(file)[0] == '_' {
 			continue
 		}
+
+		// Skip any directories that happen to be named ".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) {

Wondering if there's a preferred approach. Either way I'm happy to whip up a fix and provide test cases.

ascandella added a commit to ascandella/dep that referenced this issue May 10, 2017
fillPackage is supposed to use the AST parser on individual files.
Unforntunately, `filepath.Glob("*.go")` returns directories as well as
files.

Fixes golang#550
@ascandella ascandella changed the title dep init/ensure fails when project contains a directory named ".go" gps.ListPackages fails when project contains a directory named ".go" May 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant