Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Superficial remove prevents later remove #98

Open
rbiro-alarm opened this issue Apr 2, 2022 · 0 comments
Open

Superficial remove prevents later remove #98

rbiro-alarm opened this issue Apr 2, 2022 · 0 comments

Comments

@rbiro-alarm
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant