Skip to content

Instantly share code, notes, and snippets.

@fredrick
Created June 26, 2011 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrick/1048041 to your computer and use it in GitHub Desktop.
Save fredrick/1048041 to your computer and use it in GitHub Desktop.
--- pyinotify.py.orig 2011-06-26 12:57:41.000000000 +0100
+++ pyinotify.py.new6 2011-06-26 17:17:56.000000000 +0100
@@ -69,6 +69,7 @@
import re
import asyncore
import glob
+import hashlib
try:
from functools import reduce
@@ -1729,6 +1730,9 @@
"""
self._exclude_filter = exclude_filter
self._wmd = {} # watch dict key: watch descriptor, value: watch
+ self._wmdp = {} # watch dict key: sha(watch path), value: watch descriptor
+ self._wmdpr = {} # watch dict key: watch descriptor, value: sha(watch path)
+
self._inotify_wrapper = INotifyWrapper.create()
if self._inotify_wrapper is None:
@@ -1778,6 +1782,8 @@
"""
try:
del self._wmd[wd]
+ del self._wmdp[self._wmdpr[wd]]
+ del self._wmdpr[wd]
except KeyError, err:
log.error(str(err))
@@ -1816,6 +1822,9 @@
watch = Watch(wd=wd, path=path, mask=mask, proc_fun=proc_fun,
auto_add=auto_add, exclude_filter=exclude_filter)
self._wmd[wd] = watch
+ tpath = hashlib.sha1(path).digest()
+ self._wmdp[tpath] = wd
+ self._wmdpr[wd] = tpath
log.debug('New %s', watch)
return wd
@@ -2039,10 +2048,9 @@
@return: WD or None.
@rtype: int or None
"""
- path = self.__format_path(path)
- for iwd in self._wmd.items():
- if iwd[1].path == path:
- return iwd[0]
+ path = hashlib.sha1(self.__format_path(path)).digest()
+ if path in self._wmdp:
+ return self._wmdp[path]
def get_path(self, wd):
"""
@@ -2113,6 +2121,8 @@
# Remove watch from our dictionary
if awd in self._wmd:
del self._wmd[awd]
+ del self._wmdp[self._wmdpr[awd]]
+ del self._wmdpr[awd]
ret_[awd] = True
log.debug('Watch WD=%d (%s) removed', awd, self.get_path(awd))
return ret_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment