Skip to content

Commit

Permalink
Merge pull request #17 from tarosky/issue/16
Browse files Browse the repository at this point in the history
Ignore NFS cache when doing stat()
Close #16.
  • Loading branch information
harai authored Feb 3, 2021
2 parents bc6f276 + 55dc055 commit cda9fee
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions nudged.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ func (w *ResWriter) WriteHeader(statusCode int) {
log.Debug("php response", zap.Int("status code", statusCode))
}

func fileInfo(path string) os.FileInfo {
// Ignore NFS cache by opening file before stat().
f, err := os.Open(path)
if err != nil {
log.Error("failed to open nudge file", zap.Error(err))
return nil
}
defer func() {
if err := f.Close(); err != nil {
log.Error("failed to close nudge file", zap.Error(err))
}
}()

st, err := f.Stat()
if err != nil {
log.Error("failed to stat nudge file", zap.Error(err))
return nil
}

return st
}

func poll(ctx context.Context, invalidate func(), file string, interval int) {
go func() {
mtime := time.Time{}
Expand All @@ -288,9 +310,8 @@ func poll(ctx context.Context, invalidate func(), file string, interval int) {
break

case <-pacemaker.C:
st, err := os.Stat(file)
if err != nil {
log.Warn("failed to stat file", zap.Error(err))
st := fileInfo(file)
if st == nil {
continue
}

Expand Down

0 comments on commit cda9fee

Please sign in to comment.