Changeset 159

Show
Ignore:
Timestamp:
12/22/08 13:52:40 (15 years ago)
Author:
broder
Message:

Make pyHesiodFS cache mounted filesystems on a per-user basis

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/pyhesiodfs/pyHesiodFS.py

    • Property svn:executable set to *
    r157 r159  
    1717import hesiod 
    1818 
     19try: 
     20    from collections import defaultdict 
     21except ImportError: 
     22    class defaultdict(dict): 
     23        """ 
     24        A dictionary that automatically will fill in keys that don't exist 
     25        with the result from some default value factory 
     26         
     27        Based on the collections.defaultdict object in Python 2.5 
     28        """ 
     29         
     30        def __init__(self, default_factory): 
     31            self.default_factory = default_factory 
     32            super(defaultdict, self).__init__() 
     33         
     34        def __getitem__(self, y): 
     35            if y not in self: 
     36                self[y] = self.default_factory() 
     37            return super(defaultdict, self).__getitem__(y) 
     38         
     39        def __str__(self): 
     40            print 'defaultdict(%s, %s)' % (self.default_factory,  
     41                                           super(defaultdict, self).__str__()) 
     42         
    1943new_fuse = hasattr(fuse, '__version__') 
    2044 
     
    6690            self.fuse_args.add("volname", "MIT") 
    6791            self.fuse_args.add("fsname", "pyHesiodFS") 
    68         self.mounts = {} 
     92        self.mounts = defaultdict(dict) 
     93     
     94    def _user(self): 
     95        return fuse.FuseGetContext()['uid'] 
    6996     
    7097    def getattr(self, path): 
     
    92119 
    93120    def getCachedLockers(self): 
    94         return self.mounts.keys() 
     121        return self.mounts[self._user()].keys() 
    95122 
    96123    def findLocker(self, name): 
    97124        """Lookup a locker in hesiod and return its path""" 
    98         if name in self.mounts
    99             return self.mounts[name] 
     125        if name in self.mounts[self._user()]
     126            return self.mounts[self._user()][name] 
    100127        else: 
    101128            try: 
     
    114141                    return None 
    115142                else: 
    116                     self.mounts[name] = pointer['location'] 
     143                    self.mounts[self._user()][name] = pointer['location'] 
    117144                    syslog(LOG_INFO, "Mounting "+name+" on "+pointer['location']) 
    118145                    return pointer['location']