Skip to content

Commit b8579a5

Browse files
committed
fix panic when file/dir is deleted
Applied patch from radovskyb#96
1 parent 7893ada commit b8579a5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

watcher.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,12 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
504504
if err != nil {
505505
if os.IsNotExist(err) {
506506
w.mu.Unlock()
507-
if name == err.(*os.PathError).Path {
508-
w.Error <- ErrWatchedFileDeleted
509-
w.RemoveRecursive(name)
507+
pathErr, ok := err.(*os.PathError)
508+
if ok {
509+
if name == pathErr.Path {
510+
w.Error <- ErrWatchedFileDeleted
511+
w.RemoveRecursive(name)
512+
}
510513
}
511514
w.mu.Lock()
512515
} else {
@@ -518,9 +521,12 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
518521
if err != nil {
519522
if os.IsNotExist(err) {
520523
w.mu.Unlock()
521-
if name == err.(*os.PathError).Path {
522-
w.Error <- ErrWatchedFileDeleted
523-
w.Remove(name)
524+
pathErr, ok := err.(*os.PathError)
525+
if ok {
526+
if name == pathErr.Path {
527+
w.Error <- ErrWatchedFileDeleted
528+
w.Remove(name)
529+
}
524530
}
525531
w.mu.Lock()
526532
} else {

0 commit comments

Comments
 (0)