浏览代码

Make tombstone optional on delete.

Stefano Cossu 7 年之前
父节点
当前提交
832aed4a2a
共有 2 个文件被更改,包括 19 次插入11 次删除
  1. 5 1
      lakesuperior/endpoints/ldp.py
  2. 14 10
      lakesuperior/model/ldpr.py

+ 5 - 1
lakesuperior/endpoints/ldp.py

@@ -247,8 +247,12 @@ def delete_resource(uuid):
     repr_opts = {'parameters' : {'include' : Ldpr.RETURN_INBOUND_REF_URI}} \
             if current_app.config['store']['ldp_rs']['referential_integrity'] \
             else None
+    prefer = Toolbox().parse_rfc7240(request.headers['prefer'])
+    leave_tstone = 'no-tombstone' not in prefer
+    import pdb; pdb.set_trace()
+
     try:
-        Ldpr.inst(uuid, repr_opts).delete()
+        Ldpr.inst(uuid, repr_opts).delete(leave_tstone=leave_tstone)
     except ResourceNotExistsError as e:
         return str(e), 404
     except TombstoneError as e:

+ 14 - 10
lakesuperior/model/ldpr.py

@@ -433,7 +433,7 @@ class Ldpr(metaclass=ABCMeta):
 
     @transactional
     @must_exist
-    def delete(self, inbound=True, delete_children=True):
+    def delete(self, inbound=True, delete_children=True, leave_tstone=True):
         '''
         https://www.w3.org/TR/ldp/#ldpr-HTTP_DELETE
 
@@ -449,12 +449,13 @@ class Ldpr(metaclass=ABCMeta):
         children = self.imr[nsc['ldp'].contains * '+'] \
                 if delete_children else []
 
-        ret = self._delete_rsrc(inbound)
+        ret = self._delete_rsrc(inbound, leave_tstone)
 
         for child_uri in children:
             child_rsrc = Ldpr.inst(
                 Toolbox().uri_to_uuid(child_uri.identifier), self.repr_opts)
-            child_rsrc._delete_rsrc(inbound, tstone_pointer=self.urn)
+            child_rsrc._delete_rsrc(inbound, leave_tstone,
+                    tstone_pointer=self.urn)
 
         return ret
 
@@ -506,7 +507,7 @@ class Ldpr(metaclass=ABCMeta):
         return self.RES_UPDATED
 
 
-    def _delete_rsrc(self, inbound, tstone_pointer=None):
+    def _delete_rsrc(self, inbound, leave_tstone=True, tstone_pointer=None):
         '''
         Delete a single resource and create a tombstone.
 
@@ -520,13 +521,16 @@ class Ldpr(metaclass=ABCMeta):
         remove_trp = set(self.imr.graph)
         add_trp = set()
 
-        if tstone_pointer:
-            add_trp.add((self.urn, nsc['fcsystem'].tombstone, tstone_pointer))
+        if leave_tstone:
+            if tstone_pointer:
+                add_trp.add((self.urn, nsc['fcsystem'].tombstone,
+                        tstone_pointer))
+            else:
+                ts = Literal(arrow.utcnow(), datatype=XSD.dateTime)
+                add_trp.add((self.urn, RDF.type, nsc['fcsystem'].Tombstone))
+                add_trp.add((self.urn, nsc['fcrepo'].created, ts))
         else:
-            ts = Literal(arrow.utcnow(), datatype=XSD.dateTime)
-            add_trp.add((self.urn, RDF.type, nsc['fcsystem'].Tombstone))
-            add_trp.add((self.urn, nsc['fcrepo'].created, ts))
-
+            self._logger.info('NOT leaving tombstone.')
 
         if inbound:
             for ib_rsrc_uri in self.imr.graph.subjects(None, self.urn):