Changeset 165 for trunk/source
- Timestamp:
- 12/30/08 00:32:25 (16 years ago)
- Files:
-
- trunk/source/pyhesiodfs/pyHesiodFS.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/source/pyhesiodfs/pyHesiodFS.py
r163 r165 38 38 39 39 def __str__(self): 40 print'defaultdict(%s, %s)' % (self.default_factory,41 super(defaultdict, self).__str__())40 return 'defaultdict(%s, %s)' % (self.default_factory, 41 super(defaultdict, self).__str__()) 42 42 43 43 class negcache(dict): … … 49 49 """ 50 50 51 def __init__(self, cache_time ):51 def __init__(self, cache_time=0.5): 52 52 self.cache_time = cache_time 53 53 … … 56 56 57 57 def remove(self, obj): 58 del self[obj] 58 try: 59 del self[obj] 60 except KeyError: 61 pass 59 62 60 63 def __contains__(self, k): … … 119 122 # Cache deletions for half a second - should give `ln -nsf` 120 123 # enough time to make a new symlink 121 self.negcache = negcache(0.5)122 123 def _u ser(self):124 self.negcache = defaultdict(negcache) 125 126 def _uid(self): 124 127 return fuse.FuseGetContext()['uid'] 128 129 def _gid(self): 130 return fuse.FuseGetContext()['gid'] 131 132 def _pid(self): 133 return fuse.FuseGetContext()['pid'] 125 134 126 135 def getattr(self, path): 127 136 st = MyStat() 128 137 if path == '/': 129 st.st_mode = stat.S_IFDIR | 0777 138 st.st_mode = stat.S_IFDIR | 0775 139 st.st_gid = self._gid() 130 140 st.st_nlink = 2 131 141 elif path == hello_path: … … 134 144 st.st_size = len(hello_str) 135 145 elif '/' not in path[1:]: 136 if path[1:] not in self.negcache and self.findLocker(path[1:]):146 if path[1:] not in self.negcache[self._pid()] and self.findLocker(path[1:]): 137 147 st.st_mode = stat.S_IFLNK | 0777 138 st.st_uid = self._u ser()148 st.st_uid = self._uid() 139 149 st.st_nlink = 1 140 150 st.st_size = len(self.findLocker(path[1:])) … … 149 159 150 160 def getCachedLockers(self): 151 return self.mounts[self._u ser()].keys()161 return self.mounts[self._uid()].keys() 152 162 153 163 def findLocker(self, name): 154 164 """Lookup a locker in hesiod and return its path""" 155 if name in self.mounts[self._u ser()]:156 return self.mounts[self._u ser()][name]165 if name in self.mounts[self._uid()]: 166 return self.mounts[self._uid()][name] 157 167 else: 158 168 try: … … 171 181 return None 172 182 else: 173 self.mounts[self._u ser()][name] = pointer['location']183 self.mounts[self._uid()][name] = pointer['location'] 174 184 syslog(LOG_INFO, "Mounting "+name+" on "+pointer['location']) 175 185 return pointer['location'] … … 211 221 return -errno.EPERM 212 222 elif '/' not in path[1:]: 213 self.mounts[self._user()][path[1:]] = src 214 self.negcache.remove(path[1:]) 215 print self.mounts[self._user()] 223 self.mounts[self._uid()][path[1:]] = src 224 self.negcache[self._pid()].remove(path[1:]) 216 225 else: 217 226 return -errno.EPERM … … 221 230 return -errno.EPERM 222 231 elif '/' not in path[1:]: 223 del self.mounts[self._u ser()][path[1:]]224 self.negcache .add(path[1:])232 del self.mounts[self._uid()][path[1:]] 233 self.negcache[self._pid()].add(path[1:]) 225 234 else: 226 235 return -errno.EPERM