Use the new minetest.safe_file_write API if possible when saving database.

This commit is contained in:
red-001 2018-02-04 16:30:41 +00:00
parent 289d0e623c
commit d90fa7355c
No known key found for this signature in database
GPG Key ID: 0CBE03CD90F44222

View File

@ -3,6 +3,18 @@ function areas:player_exists(name)
return minetest.get_auth_handler().get_auth(name) ~= nil return minetest.get_auth_handler().get_auth(name) ~= nil
end 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 -- Save the areas table to a file
function areas:save() function areas:save()
local datastr = minetest.serialize(self.areas) local datastr = minetest.serialize(self.areas)
@ -10,12 +22,7 @@ function areas:save()
minetest.log("error", "[areas] Failed to serialize area data!") minetest.log("error", "[areas] Failed to serialize area data!")
return return
end end
local file, err = io.open(self.config.filename, "w") return safe_file_write(self.config.filename, datastr)
if err then
return err
end
file:write(datastr)
file:close()
end end
-- Load the areas table from the save file -- Load the areas table from the save file