Index: /trunk/source/pyhesiodfs/pyHesiodFS.py =================================================================== --- /trunk/source/pyhesiodfs/pyHesiodFS.py (revision 160) +++ /trunk/source/pyhesiodfs/pyHesiodFS.py (revision 161) @@ -10,5 +10,5 @@ # -import sys, os, stat, errno +import sys, os, stat, errno, time from syslog import * import fuse @@ -40,5 +40,30 @@ print 'defaultdict(%s, %s)' % (self.default_factory, super(defaultdict, self).__str__()) - + +class negcache(dict): + """ + A set-like object that automatically expunges entries after + they're been there for a certain amount of time. + + This only supports add, remove, and __contains__ + """ + + def __init__(self, cache_time): + self.cache_time = cache_time + + def add(self, obj): + self[obj] = time.time() + + def remove(self, obj): + del self[obj] + + def __contains__(self, k): + if super(negcache, self).__contains__(k): + if self[k] + self.cache_time > time.time(): + return True + else: + del self[k] + return False + new_fuse = hasattr(fuse, '__version__') @@ -91,4 +116,8 @@ self.fuse_args.add("fsname", "pyHesiodFS") self.mounts = defaultdict(dict) + + # Cache deletions for 10 seconds - should give people time to + # make a new symlink + self.negcache = negcache(10) def _user(self): @@ -105,5 +134,5 @@ st.st_size = len(hello_str) elif '/' not in path[1:]: - if self.findLocker(path[1:]): + if path[1:] not in self.negcache and self.findLocker(path[1:]): st.st_mode = stat.S_IFLNK | 0777 st.st_uid = self._user() @@ -183,4 +212,5 @@ elif '/' not in path[1:]: del self.mounts[self._user()][path[1:]] + self.negcache.add(path[1:]) else: return -errno.EPERM