소스 검색

Fix recursion error in inbound lookup; fix delete indexing.

Stefano Cossu 7 년 전
부모
커밋
209f26f5b2

+ 4 - 3
lakesuperior/model/ldpr.py

@@ -429,8 +429,9 @@ class Ldpr(metaclass=ABCMeta):
         refint = self.rdfly.config['referential_integrity']
         inbound = True if refint else inbound
 
-        children = (self.rdfly.get_recursive(self.uid, nsc['ldp'].contains)
-                if delete_children else [])
+        children = (
+            self.rdfly.get_recursive_children(self.uid, nsc['ldp'].contains)
+            if delete_children else [])
 
         if leave_tstone:
             ret = self._bury_rsrc(inbound)
@@ -440,7 +441,7 @@ class Ldpr(metaclass=ABCMeta):
         for child_uri in children:
             try:
                 child_rsrc = LdpFactory.from_stored(
-                    g.tbox.uri_to_uuid(child_uri.identifier),
+                    g.tbox.uri_to_uuid(child_uri),
                     repr_opts={'incl_children' : False})
             except (TombstoneError, ResourceNotExistsError):
                 continue

+ 1 - 1
lakesuperior/store_layouts/ldp_rs/lmdb_store.py

@@ -1061,7 +1061,6 @@ class LmdbStore(Store):
             's:po': (sk, pok),
             'p:so': (pk, sok),
             'o:sp': (ok, spk),
-            'c:spo': (ck, spok),
         }
 
         # Add or remove context association.
@@ -1089,6 +1088,7 @@ class LmdbStore(Store):
                 'Index action \'{}\' is not supported.'.format(action))
 
         # Add or remove triple lookups.
+        #import pdb; pdb.set_trace()
         for clabel, terms in curs.items():
             with self.cur(clabel) as icur:
                 if action == 'remove':

+ 12 - 10
lakesuperior/store_layouts/ldp_rs/rsrc_centric_layout.py

@@ -4,7 +4,7 @@ from collections import defaultdict
 from itertools import chain
 
 from flask import g
-from rdflib import Graph
+from rdflib import Graph, URIRef
 from rdflib.namespace import RDF
 from rdflib.query import ResultException
 from rdflib.resource import Resource
@@ -343,24 +343,26 @@ class RsrcCentricLayout:
         yield from ib_rels
 
 
-    def get_recursive(self, uid, predicate):
+    def get_recursive_children(self, uid, predicate):
         '''
-        Get recursive references for a resource predicate.
+        Get recursive children for a resource predicate.
 
-        @param uid (stirng) Resource UID.
+        @param uid (string) Resource UID.
         @param predicate (URIRef) Predicate URI.
         '''
         ds = self.ds
-        uri = nsc['fcres'][uid]
-        def recurse(dset, s, p):
-            new_dset = set(ds[s : p])
+        subj_uri = nsc['fcres'][uid]
+        ctx_uri = nsc['fcstruct'][uid]
+        def recurse(dset, s, p, c):
+            new_dset = set(ds.graph(c)[s : p])
             for ss in new_dset:
                 dset.add(ss)
-                if set(ds[ss : p]):
-                    recurse(dset, ss, p)
+                cc = URIRef(ss.replace(nsc['fcres'], nsc['fcstruct']))
+                if set(ds.graph(cc)[ss : p]):
+                    recurse(dset, ss, p, cc)
             return dset
 
-        return recurse(set(), uri, predicate)
+        return recurse(set(), subj_uri, predicate, ctx_uri)
 
 
     def patch_rsrc(self, uid, qry):

+ 8 - 4
tests/endpoints/test_ldp.py

@@ -379,8 +379,10 @@ class TestLdp:
         Test response codes for resources deleted recursively and their
         tombstones.
         '''
+        child_suffixes = ('a', 'a/b', 'a/b/c', 'a1', 'a1/b1')
         self.client.put('/ldp/test_delete_recursive01')
-        self.client.put('/ldp/test_delete_recursive01/a')
+        for cs in child_suffixes:
+            self.client.put('/ldp/test_delete_recursive01/{}'.format(cs))
 
         self.client.delete('/ldp/test_delete_recursive01')
 
@@ -390,9 +392,11 @@ class TestLdp:
             '<{}/test_delete_recursive01/fcr:tombstone>; rel="hasTombstone"'\
             .format(g.webroot)
 
-        child_tstone_resp = self.client.get('/ldp/test_delete_recursive01/a')
-        assert child_tstone_resp.status_code == tstone_resp.status_code
-        assert 'Link' not in child_tstone_resp.headers.keys()
+        for cs in child_suffixes:
+            child_tstone_resp = self.client.get(
+                    '/ldp/test_delete_recursive01/{}'.format(cs))
+            assert child_tstone_resp.status_code == tstone_resp.status_code
+            assert 'Link' not in child_tstone_resp.headers.keys()
 
 
     def test_put_fragments(self):