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

Improved single file monitoring. #83

Closed
wants to merge 3 commits into from
Closed

Improved single file monitoring. #83

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 25, 2020

Hi,

I found that the Inotify class is not doing a great job in single file monitoring.

According to man inotify :

           IN_IGNORED
                  Watch  was removed explicitly (inotify_rm_watch(2)) or auto‐
                  matically (file was deleted, or filesystem  was  unmounted).

The event IN_IGNORED is generated when a watch has been automatically removed, this happens when the monitored file is removed, and it also happens when user modify the monitored file with text editors that will replace the original file while saving (such as vim).

But the Inotify class itself doesn't handle this event, so the consequence is: when this happens, the watch has been automatically removed by the kernel but it still exists in the Inotify class (in Inotify.__watches and Inotify.__watches_r), and this causes a bug, when a monitored file is removed/replaced, users can no long re-add it back into the monitoring, if they try to remove it first by calling Inotify.remove_watch() then the system call inotify_rm_watch() will return an error because the watch does not exist in the kernel space.

So, the thing I've done is giving users an optional argument to make the Inotify class handle the IN_IGNORED event and it's disabled by default.

And I changed the usage of superficial parameter in Inotify.remove_watch as well which was not being used.

@@ -231,6 +231,10 @@ def event_gen(
in self._handle_inotify_event(fd):
last_hit_s = time.time()

if handle_in_ignored and\
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make it default behavior. The user shouldn't have a choice. Reword the commit message to mention that we're specifically handling the IN_IGNORED event, now.

@@ -115,7 +115,7 @@ def remove_watch(self, path, superficial=False):

del self.__watches[path]

self.remove_watch_with_id(wd)
self.remove_watch_with_id(wd, superficial)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a separate commit since it's not related to this commit.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already resolved by #57

@ghost
Copy link
Author

ghost commented Aug 27, 2020

Hi, I reverted the original commit and did what you asked, but beware, this changes the default behavior of Inotify class and could bring some backward compatibility issue.

@ghost ghost closed this by deleting the head repository Sep 11, 2023
This pull request was closed.
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

Successfully merging this pull request may close these issues.

1 participant