Skip to content

Commit

Permalink
Avoid panic.
Browse files Browse the repository at this point in the history
  • Loading branch information
joliver committed Jan 21, 2025
1 parent c1c4888 commit 82f24be
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (this *pollingWatcher) Listen() {
func (this *pollingWatcher) update() bool {
count := 0

for index, _ := range this.filenames {
for index := range this.filenames {
lastModified := this.lastModified(this.filenames[index])
if lastModified.IsZero() {
continue // no modification time
Expand Down Expand Up @@ -84,8 +84,11 @@ func (this *pollingWatcher) update() bool {
}
func (this *pollingWatcher) lastModified(filename string) time.Time {
// simple: using last-modification timestamp instead of file hash
stat, _ := os.Stat(filename)
return stat.ModTime()
if stat, err := os.Stat(filename); err == nil {
return stat.ModTime()
}

return time.Time{}
}
func (this *pollingWatcher) sleep() bool {
// simple: polling every interval instead of watching for filesystem changes
Expand Down

0 comments on commit 82f24be

Please sign in to comment.