From cb209b0f1ecd728ae4b5a5ba48c0699fd6a02ffc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 9 Nov 2017 01:42:01 +0100 Subject: mod_storage_internal: Allow truncating deletion at the beginning or end of an archive store --- plugins/mod_storage_internal.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'plugins/mod_storage_internal.lua') diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua index c29319fc..55a4bfeb 100644 --- a/plugins/mod_storage_internal.lua +++ b/plugins/mod_storage_internal.lua @@ -191,6 +191,21 @@ function archive:delete(username, query) return item.when > query["end"]; end); end + if query.truncate then + if query.reverse then + -- Before: { 1, 2, 3, 4, 5, } + -- After: { 1, 2, 3 } + while #items > query.truncate do + table.remove(items); + end + else + -- Before: { 1, 2, 3, 4, 5, } + -- After: { 3, 4, 5 } + while #items > query.truncate do + table.remove(items, 1); + end + end + end end local count = count_before - #items; local ok, err = datamanager.list_store(username, host, self.store, items); -- cgit v1.2.3