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

Add support for watching a single file #80

Open
chrisinmtown opened this issue Jun 16, 2020 · 3 comments
Open

Add support for watching a single file #80

chrisinmtown opened this issue Jun 16, 2020 · 3 comments

Comments

@chrisinmtown
Copy link

Extend PyInotify to allow python code to watch just a file.

If I'm reading the Linux system call doc correctly, inotify() supports watching a directory or a file:

https://man7.org/linux/man-pages/man7/inotify.7.html

But adding a watch on a file causes PyInotify to throw an exception:

[Errno 20] Not a directory: '/tmp/file.json/'

Please tell me if I'm missing something obvious? Thanks for considering it.

@Agent-Hellboy
Copy link

Agent-Hellboy commented Jun 20, 2020

Hi @chrisinmtown
It doesn't work on a single file because, when we use an editor to modify the file, the editor opens a copy of the file and when we save the edited version from the text editor, the existing file is deleted and a new file of the same name is created with the modifications.

When the old file is deleted, the watch created on that file becomes invalid and it is deleted automatically.

You can see the old file being replaced by the new file if you monitor the parent directory.
There are two ways to solve it, monitor the parent directory, and print the message when modifications are done to the particular that you want to watch.
Else create a new watch on the file whenever modifications are made. When the old file is deleted, the IN_DELETE_SELF event is triggered.

Hopes you get some insight from it.
I have just copied and pasted an excerpt from an answer written by someone on StackOverflow.
Here is the link for the same: https://stackoverflow.com/questions/13351172/inotify-file-in-c

@chrisinmtown
Copy link
Author

I understand that the prereq for monitoring a file with inotify is that it must exist first. I also understand that user-facing editors may do all kinds of strange things.

Anyhow I solved my problem by switching to package notify_simple which supports watching a single file just fine.

@jabowery
Copy link

jabowery commented Nov 2, 2020

Thanks chrisinmtown. That's what I was looking for and was kind of confused by this package.

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

3 participants