Use minetest.safe_file_write() to atomically save state [Breaks MT4 compat]

This commit is contained in:
orwell96 2020-01-10 14:08:56 +01:00
parent dbaafeda3e
commit 1bb1d825f4
1 changed files with 5 additions and 8 deletions

View File

@ -343,15 +343,12 @@ advtrains.save_component = function (tbl, name)
minetest.log("error", " Failed to serialize advtrains save data!")
return
end
local temppath = advtrains.fpath.."_"..name.."~"
local file, err = io.open(temppath, "w")
if err then
minetest.log("error", " Failed to write advtrains save data to file "..temppath..": "..(err or "Unknown Error"))
return
local path = advtrains.fpath.."_"..name
local success = minetest.safe_file_write(path, datastr)
if not success then
minetest.log("error", " Failed to write advtrains save data to file "..path)
end
file:write(datastr)
file:close()
os.rename(temppath, advtrains.fpath.."_"..name)
end