# HG changeset patch # User drewp@bigasterisk.com # Date 2013-06-12 02:35:30 # Node ID 3d8ad77176ecaccad54c21fbb77cbdf7f885fa07 # Parent ba7ff8c1d8f87ba4faadbdbbc24d792ee9f99fb0 rdfdb handles file removals Ignore-this: 3f3db320b7418979f4061cb86c226573 diff --git a/bin/rdfdb b/bin/rdfdb --- a/bin/rdfdb +++ b/bin/rdfdb @@ -246,8 +246,13 @@ class WatchedFiles(object): """ 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 @@ class Db(object): 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) diff --git a/light9/rdfdb/graphfile.py b/light9/rdfdb/graphfile.py --- a/light9/rdfdb/graphfile.py +++ b/light9/rdfdb/graphfile.py @@ -15,6 +15,10 @@ class GraphFile(object): """ 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 @@ class GraphFile(object): 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 @@ class GraphFile(object): 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 @@ class GraphFile(object): 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 diff --git a/light9/rdfdb/rdflibpatch.py b/light9/rdfdb/rdflibpatch.py --- a/light9/rdfdb/rdflibpatch.py +++ b/light9/rdfdb/rdflibpatch.py @@ -81,7 +81,7 @@ def serializeQuad(g): 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])