|
From: Sandeep S. <san...@gm...> - 2013-10-08 10:40:28
|
Hello, I have been using inotify for quite some time now. I just wanted to know few things as below: I have a question specific to my project requirements. I want to monitor a directory and should be able to detect its DELETE event and MOVE event, hence I register for IN_DELETE_SELF AND IN_MOVE_SELF (along with other desired events). As you know, whenever inotify triggers with an event, it gives us the wd (watch descriptor) associated with the change. In case of directory move, I get an event for IN_MOVE_SELF, and as per project requirement I need to identify where the move happened (I mean the new location).So currently, for every directory I monitor and for every directory for which I would be interested in detecting MOVE, I store an open file descriptor associated with it and once I get the move event, then I will fetch the file-descriptor and try to get the new path as below: Int fd = open(watchPath.c_str(), O_RDONLY); //code to store a reference of file-descriptor of the monitored directory char fdpath[4096]; char path[4096]; sprintf(fdpath, "/proc/self/fd/%d", fd); ssize_t sz = readlink(fdpath, path, sizeof(path) - 1); //path will contain new location This way I can get the new path, but the side effect is, in case if I delete the directory (instead of move), I won’t get the IN_DELETE_SELF event, because there is an open file descriptor that is still open. But, if I do not store the file-descriptor, I get the IN_DELETE_SELF event, but I cannot detect the new location of move. Could you please help me resolve this issue. Thanks and Best Regards, -Sandeep |