From cf6d84eabbd37fb761177369bb485e394ddd8bbd Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Tue, 4 May 2021 17:26:20 +0200 Subject: [PATCH] abort if the map.sqlite file can't be found prevents the creation of an empty database-file, which in turn lets the minetest-engine crash closes #171 --- app/setup.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/setup.go b/app/setup.go index 0b059cc..aa56148 100644 --- a/app/setup.go +++ b/app/setup.go @@ -40,12 +40,22 @@ func Setup(p params.ParamsType, cfg *Config) *App { switch a.Worldconfig[worldconfig.CONFIG_BACKEND] { case worldconfig.BACKEND_SQLITE3: - a.Blockdb, err = sqlite.New("map.sqlite") + map_path := "map.sqlite" + + // check if the database exists, otherwise abort (nothing to render/display) + _, err := os.Stat(map_path) + if os.IsNotExist(err) { + panic("world-map does not exist, aborting") + } + + // create a new sqlite-based blockdb instance + a.Blockdb, err = sqlite.New(map_path) if err != nil { panic(err) } case worldconfig.BACKEND_POSTGRES: + // create a new postgres based blockdb a.Blockdb, err = postgres.New(a.Worldconfig[worldconfig.CONFIG_PSQL_CONNECTION]) if err != nil { panic(err)