X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=AEpy%2FFuseCache.py;fp=AEpy%2FFuseCache.py;h=420b9920fcb51e368a87e033970f7fd712aead6f;hb=f06df88629c6ae1205f522148102a0c3d04d1cf2;hp=0000000000000000000000000000000000000000;hpb=8fc49cd8badf6ceb6b6dfe03deb961cadf61839f;p=fuse-aexplorer.git diff --git a/AEpy/FuseCache.py b/AEpy/FuseCache.py new file mode 100644 index 0000000..420b992 --- /dev/null +++ b/AEpy/FuseCache.py @@ -0,0 +1,66 @@ +from stat import S_IFDIR + + +class FuseCache(): + def __init__(self): + # Initialize virtual root + self.cache = {} + + # Cache tuple: + # (dict of attrs, dict of children in folder) + + + def getattr(self, path): + paths = [p for p in path.split('/') if len(p) > 0] + #print(paths) + + # Virtual root + st = dict(st_mode=(S_IFDIR | 0o755), st_nlink=2) + + c = self.cache + for p in paths: + if c == None: + return None + + if p not in c: + return None + + (st, c) = c[p] + + return st + + + def getkids(self, path): + paths = [p for p in path.split('/') if len(p) > 0] + + c = self.cache + for p in paths: + if c == None: + return None + + if p not in c: + return None + + (_, c) = c[p] + + return c + + + # Set a cache node's children and their attributes. + # This implicitly purges any prvious children from the cache. + # Thus, those directories will be re-scanned next time. + def setkids(self, path, children): + paths = [p for p in path.split('/') if len(p) > 0] + + c = self.cache + for p in paths: + # We expect to be able to walk the path, because we can't get + # there without Linux' VFS stat'ing all directories leading up. + parent = c + (_, c) = c[p] + + if (c == self.cache): + self.cache = children + else: + (st, _) = parent[p] + parent[p] = (st, children)