With inotify
, you need to set an timeout to handle the mismatched/unpaired/foreign rename operation(eg. mv
a file into or out of a watched directory), treat them as IN_CREATE
or IN_DELETE
events.
Once I worked on a project relating to file synchronization mechanism, faced with the same issue, and solved it the same way.
IMHO, the design of inotify
API is somewhat disgusting. Take the rename operation as an example, inotify
interpretes it as TWO seperates events. :-(
According to the link you give, Linux kernel does distinguish the local/foreign rename operation, and you can achieve this using the dnotify
interface. But since dnotify
was already obsoleted by inotify
interface, I won't recommend this.
reference:
http://en.wikipedia.org/wiki/Dnotify