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
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