Use safe_file_write to save forceloaded blocks

This commit is contained in:
sfan5 2021-05-30 11:15:02 +02:00
parent f30dcdb504
commit 1bc753f655

@ -86,12 +86,6 @@ local function read_file(filename)
return core.deserialize(t) or {} return core.deserialize(t) or {}
end end
local function write_file(filename, table)
local f = io.open(filename, "w")
f:write(core.serialize(table))
f:close()
end
blocks_forceloaded = read_file(wpath.."/force_loaded.txt") blocks_forceloaded = read_file(wpath.."/force_loaded.txt")
for _, __ in pairs(blocks_forceloaded) do for _, __ in pairs(blocks_forceloaded) do
total_forceloaded = total_forceloaded + 1 total_forceloaded = total_forceloaded + 1
@ -106,7 +100,8 @@ end)
-- persists the currently forceloaded blocks to disk -- persists the currently forceloaded blocks to disk
local function persist_forceloaded_blocks() local function persist_forceloaded_blocks()
write_file(wpath.."/force_loaded.txt", blocks_forceloaded) local data = core.serialize(blocks_forceloaded)
core.safe_file_write(wpath.."/force_loaded.txt", data)
end end
-- periodical forceload persistence -- periodical forceload persistence