aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2020-01-10 14:08:56 +0100
committerorwell96 <orwell@bleipb.de>2020-01-10 14:08:56 +0100
commit1bb1d825f46af3562554c12fba35a31b9f7973ff (patch)
tree6868b99bc588fa9c06ebba2026b5080c8744eda2 /advtrains
parentdbaafeda3e02d2ffafc60e5486e5aab39b643b3d (diff)
downloadadvtrains-1bb1d825f46af3562554c12fba35a31b9f7973ff.tar.gz
advtrains-1bb1d825f46af3562554c12fba35a31b9f7973ff.tar.bz2
advtrains-1bb1d825f46af3562554c12fba35a31b9f7973ff.zip
Use minetest.safe_file_write() to atomically save state [Breaks MT4 compat]
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/init.lua13
1 files changed, 5 insertions, 8 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index c5604fd..ca9c52b 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -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