Skip to content

Commit

Permalink
fix panic when file/dir is deleted
Browse files Browse the repository at this point in the history
Applied patch from radovskyb#96
  • Loading branch information
dideler committed Apr 21, 2020
1 parent 7893ada commit b8579a5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,12 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
if err != nil {
if os.IsNotExist(err) {
w.mu.Unlock()
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.RemoveRecursive(name)
pathErr, ok := err.(*os.PathError)
if ok {
if name == pathErr.Path {
w.Error <- ErrWatchedFileDeleted
w.RemoveRecursive(name)
}
}
w.mu.Lock()
} else {
Expand All @@ -518,9 +521,12 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
if err != nil {
if os.IsNotExist(err) {
w.mu.Unlock()
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.Remove(name)
pathErr, ok := err.(*os.PathError)
if ok {
if name == pathErr.Path {
w.Error <- ErrWatchedFileDeleted
w.Remove(name)
}
}
w.mu.Lock()
} else {
Expand Down

0 comments on commit b8579a5

Please sign in to comment.