corrected bug that causes server to crash if settings or bookmark files exist but are empty

master
Kilarin 2015-07-31 15:41:08 -05:00
parent 7e5dc4bc9c
commit cb05d446f0
3 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,6 @@
This mod creates a customizable compass with user settable bookmarks and shared and admin bookmarks in multiplayer.
**Compass GPS version 2.6**
**Compass GPS version 2.7**
Echo created a compass mod back in 2012: [https://forum.minetest.net/viewtopic.php?id=3785](https://forum.minetest.net/viewtopic.php?id=3785)<p>
PilzAdams made a modification of it, which I can not find the source to, I don't know how much of PilzAdams changes made it into the later versions of Echo's mod.<p>
@ -139,6 +139,7 @@ If you use this mod, please consider reviewing it on the MineTest Mod Database.<
[https://forum.minetest.net/mmdb/mod/compassgps/](https://forum.minetest.net/mmdb/mod/compassgps/)
**Changelog:**<p>
2.7 bug fix: in a catastrophic server crash, compassgps_settings or bookmarks file could exist, but be empty. When the file exists but is empty, the table it is loaded into ends up as nil instead of empty and that causes the server to crash on startup. NOT GOOD! With bug fix, if file exists but is empty, server will start but not crash and new contents for empty file will be created. a message will appear in the debug informing server owner to restore bookmarks from backup if possible.<p>
2.6 bug fix from myoung008, type causing crashes when entering bad color.<p>
2.5 bug fix from TeTpaAka fix bug when static_spawnpoint is invalid<p>
2.4 wall mounted maps by Miner59<p>

View File

@ -1,4 +1,4 @@
[b]Compass GPS version 2.6[/b]
[b]Compass GPS version 2.7[/b]
This mod creates a customizable compass with user settable bookmarks and shared and admin bookmarks in multiplayer.
Echo created a compass mod back in 2012: [url]https://forum.minetest.net/viewtopic.php?id=3785[/url]
@ -138,6 +138,7 @@ If you use this mod, please consider reviewing it on the MineTest Mod Database.
[url]https://forum.minetest.net/mmdb/mod/compassgps/[/url]
[b]Changelog:[/b]
2.7 bug fix: in a catastrophic server crash, compassgps_settings or bookmarks file could exist, but be empty. When the file exists but is empty, the table it is loaded into ends up as nil instead of empty and that causes the server to crash on startup. NOT GOOD! With bug fix, if file exists but is empty, server will start but not crash and new contents for empty file will be created. a message will appear in the debug informing server owner to restore bookmarks from backup if possible.
2.6 bug fix from myoung008, type causing crashes when entering bad color.
2.5 bug fix from TeTpaAka fix bug when static_spawnpoint is invalid
2.4 wall mounted maps by Miner59

View File

@ -65,6 +65,13 @@ print(S("compassgps reading bookmarks"))
local file = io.open(minetest.get_worldpath().."/bookmarks", "r")
if file then
bookmarks = minetest.deserialize(file:read("*all"))
-- check if it was an empty file because empty files can crash server
if bookmarks == nil then
print("compassgps:ERROR:bookmarks file exists but is empty, will recreate")
print("compassgps: this will stop the server from crashing, but bookmarks are lost")
print("compassgps: please restore "..minetest.get_worldpath().."/bookmarks from a backup if possible")
bookmarks = { }
end
file:close()
end
@ -138,6 +145,11 @@ local settings = { }
local file = io.open(minetest.get_worldpath().."/compassgps_settings", "r")
if file then
settings = minetest.deserialize(file:read("*all"))
-- check if it was an empty file because empty files can crash server
if settings == nil then
print("compassgps:ERROR:compassgps_setting file exists but is empty, will recreate")
settings = { }
end
file:close()
end
--now transfer these to the correct variables