mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-22 04:42:23 +01:00
Use the new minetest.safe_file_write
API if possible when saving database.
This commit is contained in:
parent
2637876555
commit
09c030352f
19
internal.lua
19
internal.lua
@ -3,6 +3,18 @@ function areas:player_exists(name)
|
||||
return minetest.get_auth_handler().get_auth(name) ~= nil
|
||||
end
|
||||
|
||||
local safe_file_write = minetest.safe_file_write
|
||||
if safe_file_write == nil then
|
||||
function safe_file_write(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:save()
|
||||
local datastr = minetest.serialize(self.areas)
|
||||
@ -10,12 +22,7 @@ function areas:save()
|
||||
minetest.log("error", "[areas] Failed to serialize area data!")
|
||||
return
|
||||
end
|
||||
local file, err = io.open(self.config.filename, "w")
|
||||
if err then
|
||||
return err
|
||||
end
|
||||
file:write(datastr)
|
||||
file:close()
|
||||
return safe_file_write(self.config.filename, datastr)
|
||||
end
|
||||
|
||||
-- Load the areas table from the save file
|
||||
|
Loading…
Reference in New Issue
Block a user