Skip to content

Commit 1bc753f

Browse files
committedMay 30, 2021
Use safe_file_write to save forceloaded blocks
1 parent f30dcdb commit 1bc753f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed
 

‎builtin/game/forceloading.lua

+2-7
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ local function read_file(filename)
8686
return core.deserialize(t) or {}
8787
end
8888

89-
local function write_file(filename, table)
90-
local f = io.open(filename, "w")
91-
f:write(core.serialize(table))
92-
f:close()
93-
end
94-
9589
blocks_forceloaded = read_file(wpath.."/force_loaded.txt")
9690
for _, __ in pairs(blocks_forceloaded) do
9791
total_forceloaded = total_forceloaded + 1
@@ -106,7 +100,8 @@ end)
106100

107101
-- persists the currently forceloaded blocks to disk
108102
local function persist_forceloaded_blocks()
109-
write_file(wpath.."/force_loaded.txt", blocks_forceloaded)
103+
local data = core.serialize(blocks_forceloaded)
104+
core.safe_file_write(wpath.."/force_loaded.txt", data)
110105
end
111106

112107
-- periodical forceload persistence

0 commit comments

Comments
 (0)
Please sign in to comment.