util.datamanager: Add way to close indexed list store
authorKim Alvefur <zash@zash.se>
Fri, 21 Jul 2023 18:30:06 +0200
changeset 13240 9c72f93b7a02
parent 13239 dbd7a6b09ada
child 13241 59c3d775c7fa
util.datamanager: Add way to close indexed list store
util/datamanager.lua
--- a/util/datamanager.lua	Fri Jul 21 18:28:54 2023 +0200
+++ b/util/datamanager.lua	Fri Jul 21 18:30:06 2023 +0200
@@ -461,6 +461,13 @@
 	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 @@
 	__len = function(t)
 		return #t.index;
 	end;
+	__close = list_close;
 }
 
 local function list_load(username, host, datastore)
@@ -516,7 +524,7 @@
 		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)