aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-07-16 17:17:18 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-07-16 17:17:18 +0200
commit7a6740eb8c8e6902d1379273ba9dc7c4c2c14cdf (patch)
tree91baf60f14c482a98d81def5415ab38cbd19a408
parent053fd91fe02899deb82e93120a26c44a2535f188 (diff)
downloadadvtrains-7a6740eb8c8e6902d1379273ba9dc7c4c2c14cdf.tar.gz
advtrains-7a6740eb8c8e6902d1379273ba9dc7c4c2c14cdf.tar.bz2
advtrains-7a6740eb8c8e6902d1379273ba9dc7c4c2c14cdf.zip
Keep a backup file where stuff is written to when saving
This should prevent yet another train service disaster.
-rw-r--r--advtrains/init.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 3fc0de0..2bcfb0c 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -358,14 +358,15 @@ advtrains.avt_save = function(remove_players_from_wagons)
minetest.log("error", " Failed to serialize advtrains save data!")
return
end
- local file, err = io.open(advtrains.fpath, "w")
+ local temppath = advtrains.fpath.."~"
+ local file, err = io.open(temppath, "w")
if err then
- minetest.log("error", " Failed to write advtrains save data to file "..advtrains.fpath..": "..(err or "Unknown Error"))
+ minetest.log("error", " Failed to write advtrains save data to file "..temppath..": "..(err or "Unknown Error"))
return
end
file:write(datastr)
file:close()
-
+ os.rename(temppath, advtrains.fpath)
if DUMP_DEBUG_SAVE then
local file, err = io.open(advtrains.fpath.."_DUMP", "w")
if err then