commit 7468ff73a5e43878de71b48aeb6015177dc7d252
parent 6d5d790da10ae8407564d491633c526ca8aa9259
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sat, 29 Dec 2012 00:55:32 +0100
fix bug of insufficient cache invalidation
Diffstat:
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/metacachefs.py b/metacachefs.py
@@ -7,6 +7,8 @@ import errno
import os
import sys
from loopfs import LoopFS
+import traceback
+import logging
fuse.fuse_python_api = (0, 2)
@@ -20,6 +22,7 @@ class MissingNode:
class Node:
def __init__(self):
self.flush()
+ self.potentialChildren = set()
def flush(self):
self.access = None
@@ -30,6 +33,9 @@ class Node:
def flushFolder(self):
self.readdir = None
+ def registerChild(self, path):
+ self.potentialChildren.add(path)
+
class MetaCacheFS(LoopFS):
def __init__(self, *args, **kw):
@@ -38,6 +44,7 @@ class MetaCacheFS(LoopFS):
def flushIfPresent(self, path):
if path in self.files.keys():
+ self.doFlushFolder(path)
self.files[path].flush()
def deleteIfPresent(self, path):
if path in self.files.keys():
@@ -47,8 +54,20 @@ class MetaCacheFS(LoopFS):
return head
def flushFolder(self, path):
+ logging.debug("flushing %s" % (self.getFolder(path)))
if self.getFolder(path) in self.files.keys():
- self.files[self.getFolder(path)].flushFolder()
+ return self.doFlushFolder(self.getFolder(path))
+
+ def doFlushFolder(self, path):
+ d = self.files[path]
+ if d.readdir != None:
+ for x in d.readdir:
+ logging.debug("flushing descendent %s" % (os.path.join(path, x.name)))
+ self.flushIfPresent(os.path.join(path, x.name))
+ for x in d.potentialChildren:
+ logging.debug("flushing potential descendent %s" % x)
+ self.flushIfPresent(x)
+ d.flushFolder()
def exceptionToStatus(self, e):
if isinstance(e, OSError):
@@ -61,10 +80,16 @@ class MetaCacheFS(LoopFS):
head, tail = os.path.split(path)
if head in self.files.keys():
d = self.files[head]
+ logging.debug("might get missingfile from %s, index is %s" % (
+ head, d.readdir))
if d.readdir != None and tail not in [x.name for x in
d.readdir]:
return MissingNode() # we know it can't exist
+ logging.debug("created fresh node for %s" % path)
self.files[path] = Node()
+ if (head != path):
+ headFile = self.getOrCreate(head)
+ headFile.registerChild(path)
return self.files[path]
def access(self, path, mode):
@@ -91,7 +116,9 @@ class MetaCacheFS(LoopFS):
def getattr(self, path):
pathh = os.path.normpath(path)
+ logging.debug("pathh is %s in cache" % "" if pathh in self.files.keys() else " not")
f = self.getOrCreate(pathh)
+ logging.debug("my file has %s" % f.getattr)
if f.getattr == None:
try:
x = super(MetaCacheFS, self).getattr(path)
@@ -193,6 +220,7 @@ if __name__ == "__main__":
#logging.getLogger().setLevel(logging.DEBUG)
#cachefs = CacheFS(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
+ logging.basicConfig(level=logging.DEBUG)
metacachefs = MetaCacheFS()
fuse_opts = metacachefs.parse(['-o', 'fsname=metacachefs'] + sys.argv[1:])
metacachefs.main()