Skip to content

Commit

Permalink
Fix retrieveFilelist for the instances where files are deleted in
Browse files Browse the repository at this point in the history
between retrieving file names and stat during filepath.Walk
  • Loading branch information
radovskyb committed Jan 15, 2019
1 parent 593985f commit d8b41ca
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
list, err = w.listRecursive(name)
if err != nil {
if os.IsNotExist(err) {
w.Error <- ErrWatchedFileDeleted
w.mu.Unlock()
w.RemoveRecursive(err.(*os.PathError).Path)
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.RemoveRecursive(name)

This comment has been minimized.

Copy link
@tomek-cz

tomek-cz Jan 25, 2019

Hi @radovskyb, it look like you're removing the whole watched directory here form the list? I am hitting an issue where in case of ErrWatchedFileDeleted the watcher stops reporting new events for the directory I am watching.

This comment has been minimized.

Copy link
@tomek-cz

tomek-cz Jan 25, 2019

Actually I have been testing release 1.0.5 and that change is not there yet ? I am going to test the master.

This comment has been minimized.

Copy link
@radovskyb

radovskyb Jan 26, 2019

Author Owner

Hi @tomek-cz, how did you go testing? These changes should now be in v1.0.6 :)

This comment has been minimized.

Copy link
@tomek-cz

tomek-cz Jan 28, 2019

It is much better, thanks. The ErrWatchedFileDeleted errors are now gracefully handled, no deadlock :-) while moving files at all now, which is great (I am moving newly created files). What I have discovered now is that sometimes the CREATE event would be triggered twice for the same file, so my 'move' process would fail, but I can handle that... BTW I only move files if its 'modify time' timestamp is older than 30 seconds. So, the deadlock issue is gone for me. And I have been testing that pretty heavily.

}
w.mu.Lock()
} else {
w.Error <- err
Expand All @@ -507,9 +509,11 @@ func (w *Watcher) retrieveFileList() map[string]os.FileInfo {
list, err = w.list(name)
if err != nil {
if os.IsNotExist(err) {
w.Error <- ErrWatchedFileDeleted
w.mu.Unlock()
w.Remove(err.(*os.PathError).Path)
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.Remove(name)
}
w.mu.Lock()
} else {
w.Error <- err
Expand Down

0 comments on commit d8b41ca

Please sign in to comment.