forked from minetest-mods/areas
Move areas:save() into async
On newer Minetest servers, handles saving jobs in async environment. To prevent conflicts, the save file is locked whie saving, and if a code requests saving while the file is locked, data is saved again immediately after finishing the current save.
This commit is contained in:
23
async.lua
Normal file
23
async.lua
Normal file
@ -0,0 +1,23 @@
|
||||
areas = rawget(_G, "areas") or {}
|
||||
|
||||
local safe_file_write = core.safe_file_write
|
||||
if safe_file_write == nil then
|
||||
safe_file_write = function(path, content)
|
||||
local file, err = io.open(path, "w")
|
||||
if err then
|
||||
return err
|
||||
end
|
||||
file:write(content)
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- Save the areas table to a file
|
||||
function areas._internal_do_save(areas_tb, filename)
|
||||
local datastr = core.write_json(areas_tb)
|
||||
if not datastr then
|
||||
core.log("error", "[areas] Failed to serialize area data!")
|
||||
return
|
||||
end
|
||||
return safe_file_write(filename, datastr)
|
||||
end
|
Reference in New Issue
Block a user