dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
245 stars 73 forks source link

InotifyTree doesn't handle mkdir()+rmdir() #22

Closed EdSchouten closed 6 years ago

EdSchouten commented 8 years ago

While using InotifyTree, I noticed that if you create and remove a directory very quickly, event_gen() fails. The reason for this is obvious: it sees the CREATE event and tries to install a new probe, which fails, as the target no longer exists.

InotifyTree should simply ignore such errors.

dsoprea commented 8 years ago

Makes sense. Please submit a PR.

On Sep 6, 2016 03:36, "EdSchouten" notifications@github.com wrote:

While using InotifyTree, I noticed that if you create and remove a directory very quickly, event_gen() fails. The reason for this is obvious: it sees the CREATE event and tries to install a new probe, which fails, as the target no longer exists.

InotifyTree should simply ignore such errors.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dsoprea/PyInotify/issues/22, or mute the thread https://github.com/notifications/unsubscribe-auth/AArral8_SeUyBKusaldOctWUPBltCb_oks5qnRfkgaJpZM4J1i37 .

dsoprea commented 8 years ago

IF you're not able to, then let me know and I can try to do something ASAP.

EdSchouten commented 8 years ago

Well, it's just something I randomly observed while experimenting with inotify. It turns out I don't need inotify anymore for my use-case, so it may be better if you looked into it. Thanks!

dsoprea commented 8 years ago

Thanks for exposing the possibility of that issue.

On Sep 6, 2016 10:55, "EdSchouten" notifications@github.com wrote:

Well, it's just something I randomly observed while experimenting with inotify. It turns out I don't need inotify anymore for my use-case, so it may be better if you looked into it. Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dsoprea/PyInotify/issues/22#issuecomment-244976854, or mute the thread https://github.com/notifications/unsubscribe-auth/AArransI8VL83d-aRphZe8oLp5RjRXt6ks5qnX7FgaJpZM4J1i37 .

dsoprea commented 8 years ago

It's not clear why you're getting an error. With each received event, we hit our dictionary of handles, and, if no entry is found, it breaks out of the loop. This is actually a mistake introduced via a PR in the past and I've just rectified it. But, I'm not sure why you'd have an error.

Can you recall the actual error?

On Tue, Sep 6, 2016 at 11:00 AM, Dustin Oprea myselfasunder@gmail.com wrote:

Thanks for exposing the possibility of that issue.

On Sep 6, 2016 10:55, "EdSchouten" notifications@github.com wrote:

Well, it's just something I randomly observed while experimenting with inotify. It turns out I don't need inotify anymore for my use-case, so it may be better if you looked into it. Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dsoprea/PyInotify/issues/22#issuecomment-244976854, or mute the thread https://github.com/notifications/unsubscribe-auth/AArransI8VL83d-aRphZe8oLp5RjRXt6ks5qnX7FgaJpZM4J1i37 .

EdSchouten commented 8 years ago

Yes!

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ed/virtualenv/local/lib/python2.7/site-packages/inotify/adapters.py", line 216, in event_gen
    self._i.add_watch(full_path, self._mask)
  File "/home/ed/virtualenv/local/lib/python2.7/site-packages/inotify/adapters.py", line 67, in add_watch
    wd = inotify.calls.inotify_add_watch(self.__inotify_fd, path, mask)
  File "/home/ed/virtualenv/local/lib/python2.7/site-packages/inotify/calls.py", line 35, in _check_nonnegative
    (result,))
inotify.calls.InotifyError: Call failed (should not be -1): (-1) ERRNO=(0)

It's fairly easy to trigger. Just get events from an InotifyTree while running rm -Rf a; mkdir -p a/b/c/d/e in a tight loop.