Author: tack
Date: Sun Apr 15 16:59:54 2007
New Revision: 2619

Modified:
   trunk/base/src/extensions/inotify/__init__.py

Log:
Handle case where event callback removes a watch for which we've already
buffered more events.  Before this would log an error, but now we keep
track of recently removed watches in order to suppress the error.  Also
add MOVED_FROM and MOVED_TO to default event mask.


Modified: trunk/base/src/extensions/inotify/__init__.py
==============================================================================
--- trunk/base/src/extensions/inotify/__init__.py       (original)
+++ trunk/base/src/extensions/inotify/__init__.py       Sun Apr 15 16:59:54 2007
@@ -33,6 +33,7 @@
 import struct
 import logging
 import fcntl
+import select
 
 # kaa imports
 import kaa.notifier
@@ -75,6 +76,11 @@
 
         self._watches = {}
         self._watches_by_path = {}
+        # We keep track of recently removed watches so we don't get confused
+        # if an event callback removes a watch while we're currently
+        # processing a batch of events and we receive an event for a watch
+        # we just removed.
+        self._watches_recently_removed = []
         self._read_buffer = ""
         self._move_state = None  # For MOVED_FROM events
         self._moved_timer = kaa.notifier.WeakOneShotTimer(self._emit_last_move)
@@ -134,6 +140,7 @@
         _inotify.rm_watch(self._fd, wd)
         del self._watches[wd]
         del self._watches_by_path[path]
+        self._watches_recently_removed.append(wd)
         return True
 
 
@@ -197,10 +204,11 @@
 
             self._read_buffer = self._read_buffer[16+size:]
             if wd not in self._watches:
-                # Weird, received an event for an unknown watch; this
-                # shouldn't happen under sane circumstances, so log this as
-                # an error.
-                log.error("INotify received event for unknown watch.")
+                if wd not in self._watches_recently_removed:
+                    # Weird, received an event for an unknown watch; this
+                    # shouldn't happen under sane circumstances, so log this as
+                    # an error.
+                    log.error("INotify received event for unknown watch.")
                 continue
 
             path = self._watches[wd][1]
@@ -236,10 +244,17 @@
             self._watches[wd][0].emit(mask, path)
             self.signals["event"].emit(mask, path)
 
-            if mask & INotify.IGNORED:
+            if mask & (INotify.IGNORED | INotify.DELETE_SELF):
                 # Self got deleted, so remove the watch data.
                 del self._watches[wd]
                 del self._watches_by_path[path]
+                self._watches_recent_removed.append(wd)
+
+        if not self._read_buffer and len(self._watches_recently_removed) and \
+           not select.select([self._fd], [], [], 0)[0]:
+            # We've processed all pending inotify events.  We can reset the
+            # recently removed watches list.
+            self._watches_recently_removed = []
 
 
 if _inotify:
@@ -250,7 +265,8 @@
 
     INotify.WATCH_MASK = INotify.MODIFY | INotify.ATTRIB | INotify.DELETE | \
                          INotify.CREATE | INotify.DELETE_SELF | \
-                         INotify.UNMOUNT | INotify.MOVE
+                         INotify.UNMOUNT | INotify.MOVE | INotify.MOVE_SELF | \
+                         INotify.MOVED_FROM | INotify.MOVED_TO
 
     INotify.CHANGE     = INotify.MODIFY | INotify.ATTRIB
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to