Skip to content

Commit

Permalink
Merge pull request golang#191 from tomwilkie/too-many-fds
Browse files Browse the repository at this point in the history
Make sure you close files after opening them.
  • Loading branch information
sdboyer authored Mar 12, 2017
2 parents dd105da + d8ac2f0 commit 87f0b75
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
// would have an err with the same path as is called this time, as only
// then will filepath.Walk have attempted to descend into the directory
// and encountered an error.
_, err = os.Open(wp)
var f *os.File
f, err = os.Open(wp)
if err != nil {
if os.IsPermission(err) {
return filepath.SkipDir
}
return err
}
f.Close()

// Compute the import path. Run the result through ToSlash(), so that
// windows file paths are normalized to slashes, as is expected of
Expand Down

0 comments on commit 87f0b75

Please sign in to comment.