summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-11-16 15:31:57 -0500
committerShadowNinja <shadowninja@minetest.net>2015-03-06 00:20:45 -0500
commit708337dfc2b3871dc6de983e781e4a4a60a1881d (patch)
tree97352d676d9d76b036d8b559ae4d3c6fe83bbf12 /src/main.cpp
parentc7454d4732dee0f7364ccb8e07002df1a037b94d (diff)
downloadminetest-708337dfc2b3871dc6de983e781e4a4a60a1881d.tar.gz
minetest-708337dfc2b3871dc6de983e781e4a4a60a1881d.tar.bz2
minetest-708337dfc2b3871dc6de983e781e4a4a60a1881d.zip
Clean up database API and save the local map on an interval
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp59
1 files changed, 26 insertions, 33 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 922effb1f..4e5bf51fd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -914,52 +914,46 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings &
static bool migrate_database(const GameParams &game_params, const Settings &cmd_args,
Server *server)
{
+ std::string migrate_to = cmd_args.get("migrate");
Settings world_mt;
- bool success = world_mt.readConfigFile((game_params.world_path
- + DIR_DELIM + "world.mt").c_str());
+ std::string world_mt_path = game_params.world_path + DIR_DELIM + "world.mt";
+ bool success = world_mt.readConfigFile(world_mt_path.c_str());
if (!success) {
errorstream << "Cannot read world.mt" << std::endl;
- return false;
+ return 1;
}
-
if (!world_mt.exists("backend")) {
- errorstream << "Please specify your current backend in world.mt file:"
- << std::endl << " backend = {sqlite3|leveldb|redis|dummy}"
- << std::endl;
- return false;
+ errorstream << "Please specify your current backend in world.mt:"
+ << std::endl;
+ errorstream << " backend = {sqlite3|leveldb|redis|dummy}"
+ << std::endl;
+ return 1;
}
-
std::string backend = world_mt.get("backend");
Database *new_db;
- std::string migrate_to = cmd_args.get("migrate");
-
if (backend == migrate_to) {
- errorstream << "Cannot migrate: new backend is same as the old one"
- << std::endl;
- return false;
+ errorstream << "Cannot migrate: new backend is same"
+ <<" as the old one" << std::endl;
+ return 1;
}
-
if (migrate_to == "sqlite3")
- new_db = new Database_SQLite3(&(ServerMap&)server->getMap(),
- game_params.world_path);
-#if USE_LEVELDB
+ new_db = new Database_SQLite3(game_params.world_path);
+ #if USE_LEVELDB
else if (migrate_to == "leveldb")
- new_db = new Database_LevelDB(&(ServerMap&)server->getMap(),
- game_params.world_path);
-#endif
-#if USE_REDIS
+ new_db = new Database_LevelDB(game_params.world_path);
+ #endif
+ #if USE_REDIS
else if (migrate_to == "redis")
- new_db = new Database_Redis(&(ServerMap&)server->getMap(),
- game_params.world_path);
-#endif
+ new_db = new Database_Redis(world_mt);
+ #endif
else {
- errorstream << "Migration to " << migrate_to << " is not supported"
- << std::endl;
- return false;
+ errorstream << "Migration to " << migrate_to
+ << " is not supported" << std::endl;
+ return 1;
}
std::vector<v3s16> blocks;
- ServerMap &old_map = ((ServerMap&)server->getMap());
+ ServerMap &old_map = (ServerMap &) server->getMap();
old_map.listAllLoadableBlocks(blocks);
int count = 0;
new_db->beginSave();
@@ -975,16 +969,15 @@ static bool migrate_database(const GameParams &game_params, const Settings &cmd_
}
++count;
if (count % 500 == 0)
- actionstream << "Migrated " << count << " blocks "
- << (100.0 * count / blocks.size()) << "% completed" << std::endl;
+ actionstream << "Migrated " << count << " blocks "
+ << (100.0 * count / blocks.size()) << "% completed" << std::endl;
}
new_db->endSave();
delete new_db;
actionstream << "Successfully migrated " << count << " blocks" << std::endl;
world_mt.set("backend", migrate_to);
- if (!world_mt.updateConfigFile(
- (game_params.world_path+ DIR_DELIM + "world.mt").c_str()))
+ if (!world_mt.updateConfigFile(world_mt_path.c_str()))
errorstream << "Failed to update world.mt!" << std::endl;
else
actionstream << "world.mt updated" << std::endl;