From 1bc753f655db4c7de030f2700361011e1c0278a5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 30 May 2021 11:15:02 +0200 Subject: Use safe_file_write to save forceloaded blocks --- builtin/game/forceloading.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/game/forceloading.lua b/builtin/game/forceloading.lua index e1e00920c..8043e5dea 100644 --- a/builtin/game/forceloading.lua +++ b/builtin/game/forceloading.lua @@ -86,12 +86,6 @@ local function read_file(filename) return core.deserialize(t) or {} 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") for _, __ in pairs(blocks_forceloaded) do total_forceloaded = total_forceloaded + 1 @@ -106,7 +100,8 @@ end) -- persists the currently forceloaded blocks to disk 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 -- periodical forceload persistence -- cgit v1.2.3