Diff

util/datamanager.lua @ 13236:9c72f93b7a02

util.datamanager: Add way to close indexed list store
author Kim Alvefur <zash@zash.se>
date Fri, 21 Jul 2023 18:30:06 +0200
parent 13235:dbd7a6b09ada
child 13238:26327eac56dc
line wrap: on
line diff
--- 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)