gorakhargosh / watchdog

Python library and shell utilities to monitor filesystem events.
http://packages.python.org/watchdog/
Apache License 2.0
6.46k stars 690 forks source link

Unwanted behavior when renaming watched directory on Windows #415

Open Ruuttu opened 7 years ago

Ruuttu commented 7 years ago

I'm watching a directory, let's say C:/mydirectory. I rename the watched directory to C:/old-trash, then create a new folder called C:/mydirectory.

Unfortunately events are no longer appearing when I create a file under C:/mydirectory. Instead watchdog is now reporting on C:/old-trash. Additionally when creating a file under C:/old-trash, the FileCreatedEvent's src_path incorrectly claims the new file is under C:/mydirectory.

This is with watchdog 0.8.3 and python 2.7.3 on Windows 7 Enterprise.

akiross commented 6 years ago

I think this is fine, as you are watching one directory whether its name remains constant or it is modified. Actually, I think this is the desired behavior. If you want to check for any directory with a given name, you can stop the observer when you detect a rename event, start a new observer in the parent directory and wait for another directory with the old name to be created, then watch that one.

Ruuttu commented 6 years ago

If it's desired behavior, there's still a bug with the post-rename events not reflecting where the events are coming from.

From my perspective it's not desired behavior, because I registered to receive events for directory X, and I'm not getting events for directory X. When creating a new observer to avoid this, there's a risk of missing some events "in-between", tho I would understand if this is unavoidable in Windows.