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
242 stars 73 forks source link

Superficial remove prevents later remove #98

Open rbiro-alarm opened 2 years ago

rbiro-alarm commented 2 years ago

If you do a superficial remove to invalidate the filename cache, you cannot later stop watching the inode. It would probably be better to just ignore the error.

!/usr/bin/env python3

import inotify.adapters import os from threading import Thread import time from inotify.constants import IN_MOVED_FROM, IN_CLOSE_WRITE

i = inotify.adapters.Inotify()

os.system("mkdir foo") os.system("touch foo/bar") watch_file = i.add_watch("foo/bar", mask=IN_CLOSE_WRITE) watch_dir = i.add_watch("foo", IN_MOVED_FROM)

i.remove_watch("foo/bar", superficial=True) i.remove_watch_with_id(watch_file)

./inotify_test.py mkdir: cannot create directory ‘foo’: File exists Traceback (most recent call last): File "./inotify_test.py", line 16, in i.remove_watch_with_id(watch_file) File "/home/rbiro/.local/lib/python3.8/site-packages/inotify/adapters.py", line 121, in remove_watch_with_id del self.__watches_r[wd] KeyError: 1