changeset 931:3d8ad77176ec

rdfdb handles file removals Ignore-this: 3f3db320b7418979f4061cb86c226573
author drewp@bigasterisk.com
date Wed, 12 Jun 2013 02:35:30 +0000
parents ba7ff8c1d8f8
children 92c6e4b6cabb
files bin/rdfdb light9/rdfdb/graphfile.py light9/rdfdb/rdflibpatch.py
diffstat 3 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/bin/rdfdb	Tue Jun 11 21:20:26 2013 +0000
+++ b/bin/rdfdb	Wed Jun 12 02:35:30 2013 +0000
@@ -246,8 +246,13 @@
         """
         warn us that a patch is about to come to this context. it's more
         straightforward to create the new file now
+
+        this is meant to make the file before we add triples, so we
+        wouldn't see the blank file and lose those triples. But it
+        didn't work, so there are other measures that make us not lose
+        the triples from a new file. Calling this before patching the
+        graph is still a reasonable thing to do, though.
         """
-    
         g = self.getSubgraph(ctx)
 
         if ctx not in self.graphFiles:
@@ -311,7 +316,7 @@
         log.info("patching graph %s -%d +%d" % (
             ctx, len(p.delQuads), len(p.addQuads)))
 
-        if hasattr(self, 'watchedFiles'): # not during startup
+        if hasattr(self, 'watchedFiles'): # not available during startup
             self.watchedFiles.aboutToPatch(ctx)
         
         patchQuads(self.graph, p.delQuads, p.addQuads, perfect=True)
--- a/light9/rdfdb/graphfile.py	Tue Jun 11 21:20:26 2013 +0000
+++ b/light9/rdfdb/graphfile.py	Wed Jun 12 02:35:30 2013 +0000
@@ -15,6 +15,10 @@
     """
     def __init__(self, notifier, path, uri, patch, getSubgraph):
         """
+        uri is the context for the triples in this file. We assume
+        sometimes that we're the only ones with triples in this
+        context.
+        
         this does not include an initial reread() call
         """
         self.path, self.uri = path, uri
@@ -32,6 +36,8 @@
             f.write("#new\n")
             f.close()
             iolog.info("%s created", path)
+            # this was supposed to cut out some extra reads but it
+            # didn't work:
             self.lastWriteTimestamp = os.path.getmtime(path)
 
 
@@ -55,8 +61,9 @@
         maskNames = humanReadableMask(mask)
         if maskNames[0] == 'delete_self':
             if not filepath.exists():
-                log.warn("%s delete_self event: need to dump the stmts from "
-                         "this file", filepath)
+                log.info("%s delete_self", filepath)
+                self.fileGone()
+                return
             else:
                 log.warn("%s delete_self event but file is here. ignoring",
                          filepath)
@@ -82,6 +89,15 @@
         except Exception:
             traceback.print_exc()
 
+    def fileGone(self):
+        """
+        our file is gone; remove the statements from that context
+        """
+        myQuads = [(s,p,o,self.uri) for s,p,o in self.getSubgraph(self.uri)]
+        log.debug("dropping all statements from context %s", self.uri)
+        if myQuads:
+            self.patch(Patch(delQuads=myQuads), dueToFileChange=True)
+            
     def reread(self):
         """update the graph with any diffs from this file
 
--- a/light9/rdfdb/rdflibpatch.py	Tue Jun 11 21:20:26 2013 +0000
+++ b/light9/rdfdb/rdflibpatch.py	Wed Jun 12 02:35:30 2013 +0000
@@ -81,7 +81,7 @@
 def inContext(graph, newContext):
     """
     make a ConjunctiveGraph where all the triples in the given graph
-    are in newContext
+    are now in newContext
     """
     return graphFromQuads([(s,p,o,newContext) for s,p,o in graph])