From e6d0a3e6390ebfb0f39394a10fb12825bcf13b20 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 21 Jul 2023 18:30:06 +0200 Subject: util.datamanager: Add way to close indexed list store --- util/datamanager.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index 3a6a462f..2fc89a79 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -461,6 +461,13 @@ local function list_load_one(fh, start, length) return item; end +local function list_close(list) + if list.index and list.index.file then + list.index.file:close(); + end + return list.file:close(); +end + local indexed_list_mt = { __index = function(t, i) if type(i) ~= "number" or i % 1 ~= 0 or i < 1 then @@ -476,6 +483,7 @@ local indexed_list_mt = { __len = function(t) return #t.index; end; + __close = list_close; } local function list_load(username, host, datastore) @@ -516,7 +524,7 @@ local function list_open(username, host, datastore) file:close() return index, err; end - return setmetatable({ file = file; index = index }, indexed_list_mt); + return setmetatable({ file = file; index = index; close = list_close }, indexed_list_mt); end local function shift_index(index_filename, index, trim_to, offset) -- cgit v1.2.3