Changeset

13238:26327eac56dc

util.datamanager: Always reset index after list shift Shifting the index does not work reliably yet, better to rebuild it from scratch. Since there is minimal parsing involved in that, it should be more efficient anyway.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Jul 2023 14:02:01 +0200 (17 months ago)
parents 13237:59c3d775c7fa
children 13239:f2578a69ccf4
files util/datamanager.lua
diffstat 1 files changed, 4 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/util/datamanager.lua	Sat Jul 22 12:08:01 2023 +0200
+++ b/util/datamanager.lua	Sat Jul 22 14:02:01 2023 +0200
@@ -527,45 +527,10 @@
 	return setmetatable({ file = file; index = index; close = list_close }, indexed_list_mt);
 end
 
-local function shift_index(index_filename, index, trim_to, offset)
-	local index_scratch = index_filename .. "~";
-	local new_index, err = io_open(index_scratch, "w");
-	if not new_index then
-		os_remove(index_filename);
-		return "deleted", err;
-	end
-
-	local ok, err = new_index:write(index_magic);
-	if not ok then
-		new_index:close();
-		os_remove(index_filename);
-		os_remove(index_scratch);
-		return "deleted", err;
-	end
-
-	if not index.file or not index.file:seek("set", index_item_size * trim_to) then
-		new_index:close();
-		os_remove(index_filename);
-		os_remove(index_scratch);
-		return "deleted";
-	else
-		local pack, unpack = string.pack, string.unpack;
-		for item in index.file:lines(index_item_size) do
-			local ok, err = new_index:write(pack(index_fmt, unpack(index_fmt, item) - offset));
-			if not ok then
-				os_remove(index_filename);
-				os_remove(index_scratch);
-				return "deleted", err;
-			end
-		end
-		local ok, err = new_index:close();
-		if not ok then
-			os_remove(index_filename);
-			os_remove(index_scratch);
-			return "deleted", err;
-		end
-		return os_rename(index_scratch, index_filename);
-	end
+local function shift_index(index_filename, index, trim_to, offset) -- luacheck: ignore 212
+	os_remove(index_filename);
+	return "deleted";
+	-- TODO move and recalculate remaining items
 end
 
 local function list_shift(username, host, datastore, trim_to)