Skip to content

Commit

Permalink
ensure filehandles are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
docwhat committed Jan 15, 2021
1 parent 3c47e87 commit aed3bd5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/filewatcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,29 @@ func hasGoFiles(path string) bool {
if err != nil {
return false
}
defer fh.Close()

for {
names, err := fh.Readdirnames(20)
switch {
case err == io.EOF:
if err := fh.Sync(); err != nil {
panic(err)
}
return false
case err != nil:
log.Warnf("failed to read directory %v: %v", path, err)
if err := fh.Sync(); err != nil {
panic(err)
}
return false
}

for _, name := range names {
if strings.HasSuffix(name, ".go") {
if err := fh.Sync(); err != nil {
panic(err)
}
return true
}
}
Expand Down

0 comments on commit aed3bd5

Please sign in to comment.