Use minetest.safe_file_write

This commit is contained in:
Lars Mueller 2021-03-30 22:26:30 +02:00
parent cd1c99c1db
commit 6df2bcf1f1

@ -6,7 +6,7 @@ function read(filename)
return content return content
end end
function write(filename, new_content) function write_unsafe(filename, new_content)
local file = io.open(filename, "w") local file = io.open(filename, "w")
if file == nil then return false end if file == nil then return false end
file:write(new_content) file:write(new_content)
@ -14,6 +14,8 @@ function write(filename, new_content)
return true return true
end end
write = minetest and minetest.safe_file_write or write_unsafe
function ensure_content(filename, ensured_content) function ensure_content(filename, ensured_content)
local content = read(filename) local content = read(filename)
if content ~= ensured_content then if content ~= ensured_content then