diff options
author | Kim Alvefur <zash@zash.se> | 2023-07-22 14:02:01 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-07-22 14:02:01 +0200 |
commit | 8cf6d8d959c314b479615e1f9157f8a3428370a9 (patch) | |
tree | 2d5958f98e8cb4aeb8669193f7bcf280877c771f | |
parent | 4891b4eea3e83ee08828a3f646f97c1b8c7fe095 (diff) | |
download | prosody-8cf6d8d959c314b479615e1f9157f8a3428370a9.tar.gz prosody-8cf6d8d959c314b479615e1f9157f8a3428370a9.zip |
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.
-rw-r--r-- | util/datamanager.lua | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index 2fc89a79..d7add98c 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -527,45 +527,10 @@ local function list_open(username, host, datastore) 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) |