Skip to content

Commit

Permalink
Don't sync read-only file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jan 16, 2021
1 parent aed3bd5 commit e4c20b8
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions internal/filewatcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,20 @@ func hasGoFiles(path string) bool {
if err != nil {
return false
}
defer fh.Close()
defer fh.Close() // nolint: errcheck // fh is opened read-only

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 e4c20b8

Please sign in to comment.