# HG changeset patch # User Kim Alvefur # Date 1690027321 -7200 # Node ID 26327eac56dc6b91862b9936b6501662eb214e2c # Parent 59c3d775c7fa1174e8a233a1a7c81f662c510445 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. diff -r 59c3d775c7fa -r 26327eac56dc util/datamanager.lua --- 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)