|
@@ -65,17 +65,18 @@ M.store_updates = function(tmp_gr, s)
|
|
|
end
|
|
|
|
|
|
|
|
|
---[[ Dump the whole archive RDF to a file stream.
|
|
|
+--[[--
|
|
|
+Dump the whole archive RDF to a file stream.
|
|
|
|
|
|
- The result is a software-agnostic RDF representation of the metadata
|
|
|
- (Turtle) compressed with GZip. The ores data folder can be backed up via
|
|
|
- OS-level file operations.
|
|
|
+The result is a software-agnostic RDF representation of the metadata
|
|
|
+(Turtle) compressed with GZip. The ores data folder can be backed up via
|
|
|
+OS-level file operations.
|
|
|
|
|
|
- The restore() function, combined with a copy of
|
|
|
- the ores folder, shall create a fully functional repo.
|
|
|
+The restore() function, combined with a copy of
|
|
|
+the ores folder, shall create a fully functional repo.
|
|
|
|
|
|
- TODO configuration backup is not yet implemented and should be included for
|
|
|
- a completely self-sufficient backup.
|
|
|
+TODO configuration backup is not yet implemented and should be included for
|
|
|
+a completely self-sufficient backup.
|
|
|
]]
|
|
|
M.dump = function(fpath, codec)
|
|
|
local fh = assert(io.open(fpath, "wb"))
|
|
@@ -83,4 +84,35 @@ M.dump = function(fpath, codec)
|
|
|
end
|
|
|
|
|
|
|
|
|
+--[[--
|
|
|
+Remove a single resource, and optionally its members.
|
|
|
+If a resource is not found, no triples are removed.
|
|
|
+
|
|
|
+@tparam id Resource ID in the shortened URI form, `par:<ID>`
|
|
|
+@tparam boolean members Whether to delete all members of this resource (with
|
|
|
+the `has_member` relationship) and, recursively, their members.
|
|
|
+
|
|
|
+@return table Set of IDs of resources removed.
|
|
|
+]]
|
|
|
+M.remove = function(id, members)
|
|
|
+ local s = term.new_iriref_ns(id)
|
|
|
+ local del_ids = {}
|
|
|
+ local function _remove(id, members)
|
|
|
+ if members then
|
|
|
+ local mds = repo.gr:term_set(
|
|
|
+ s, triple.POS_S,
|
|
|
+ model.id_to_uri.has_member, triple.POS_P
|
|
|
+ )
|
|
|
+ for m_uri in mds:iter() do _remove(m_uri, true) end
|
|
|
+ end
|
|
|
+ if (
|
|
|
+ M.gr:remove(s) > 0 -- Remove outbound
|
|
|
+ or gr:remove(nil, nil, s) > 0 -- Remove inbound
|
|
|
+ ) then del_ids[id] = true end
|
|
|
+ end
|
|
|
+
|
|
|
+ return del_ids
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
return M
|