summaryrefslogtreecommitdiff
path: root/AEpy/FuseCache.py
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2018-12-16 23:05:33 +0100
committernorly <ny-git@enpas.org>2018-12-16 23:21:11 +0100
commitf06df88629c6ae1205f522148102a0c3d04d1cf2 (patch)
tree1aa836591c2a9b34032150752218fb31e87562de /AEpy/FuseCache.py
parent8fc49cd8badf6ceb6b6dfe03deb961cadf61839f (diff)
Import first working version
Diffstat (limited to 'AEpy/FuseCache.py')
-rw-r--r--AEpy/FuseCache.py66
1 files changed, 66 insertions, 0 deletions
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)