Author: tack
Date: Fri Mar 31 18:55:51 2006
New Revision: 1375

Modified:
   trunk/beacon/src/inotify/__init__.py

Log:
Keep a dict keyed on filename and use that for ignore() to make it O(1);
also don't register multiple watches on the same dir.


Modified: trunk/beacon/src/inotify/__init__.py
==============================================================================
--- trunk/beacon/src/inotify/__init__.py        (original)
+++ trunk/beacon/src/inotify/__init__.py        Fri Mar 31 18:55:51 2006
@@ -21,6 +21,7 @@
         }
 
         self._watches = {}
+        self._watches_by_path = {}
         self._read_buffer = ""
 
         self._fd = _inotify.init()
@@ -46,6 +47,10 @@
         will get emitted.  Callbacks connected to the signal must accept 2
         arguments: notify mask and filename.
         """
+        path = os.path.realpath(path)
+        if path in self._watches_by_path:
+            return self._watches_by_path[path][0]
+
         if mask == None:
             mask = INotify.WATCH_MASK
 
@@ -54,7 +59,8 @@
             raise IOError, "Failed to add watch on '%s'" % path
 
         signal = kaa.notifier.Signal()
-        self._watches[wd] = [signal, os.path.realpath(path)]
+        self._watches[wd] = [signal, path]
+        self._watches_by_path[path] = [signal, wd]
         return signal
 
 
@@ -63,13 +69,14 @@
         Removes a watch on the given path.
         """
         path = os.path.realpath(path)
-        for wd in self._watches:
-            if path == self._watches[wd][1]:
-                _inotify.rm_watch(self._fd, wd)
-                del self._watches[wd]
-                return True
+        if path not in self._watches_by_path:
+            return False
+
+        _inotify.rm_watch(self._fd, self._watches_by_path[path][1])
+        del self._watches[wd]
+        del self._watches_by_path[path]
+        return True
 
-        return False
 
     def _handle_data(self):
         data = os.read(self._fd, 32768)


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to