From bb74da590349643403df2c99ddc2d1584d4324ad Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 6 Jan 2023 22:35:20 +0100 Subject: [PATCH] Remove old rollback migration code (#13082) --- src/rollback.cpp | 135 +---------------------------------------------- src/rollback.h | 1 - 2 files changed, 1 insertion(+), 135 deletions(-) diff --git a/src/rollback.cpp b/src/rollback.cpp index b454e40c9..7ec4b98d4 100644 --- a/src/rollback.cpp +++ b/src/rollback.cpp @@ -96,19 +96,9 @@ RollbackManager::RollbackManager(const std::string & world_path, verbosestream << "RollbackManager::RollbackManager(" << world_path << ")" << std::endl; - std::string txt_filename = world_path + DIR_DELIM "rollback.txt"; - std::string migrating_flag = txt_filename + ".migrating"; database_path = world_path + DIR_DELIM "rollback.sqlite"; - bool created = initDatabase(); - - if (fs::PathExists(txt_filename) && (created || - fs::PathExists(migrating_flag))) { - std::ofstream of(migrating_flag.c_str()); - of.close(); - migrate(txt_filename); - fs::DeleteSingleFileOrEmptyDirectory(migrating_flag); - } + initDatabase(); } @@ -670,129 +660,6 @@ const std::list RollbackManager::getActionsSince( } -void RollbackManager::migrate(const std::string & file_path) -{ - std::cout << "Migrating from rollback.txt to rollback.sqlite." << std::endl; - - std::ifstream fh(file_path.c_str(), std::ios::in | std::ios::ate); - if (!fh.good()) { - throw FileNotGoodException("Unable to open rollback.txt"); - } - - std::streampos file_size = fh.tellg(); - - if (file_size < 10) { - errorstream << "Empty rollback log." << std::endl; - return; - } - - fh.seekg(0); - - sqlite3_stmt *stmt_begin; - sqlite3_stmt *stmt_commit; - SQLOK(sqlite3_prepare_v2(db, "BEGIN", -1, &stmt_begin, NULL)); - SQLOK(sqlite3_prepare_v2(db, "COMMIT", -1, &stmt_commit, NULL)); - - std::string bit; - int i = 0; - time_t start = time(0); - time_t t = start; - SQLRES(sqlite3_step(stmt_begin), SQLITE_DONE); - sqlite3_reset(stmt_begin); - do { - ActionRow row; - row.id = 0; - - // Get the timestamp - std::getline(fh, bit, ' '); - bit = trim(bit); - if (!atoi(bit.c_str())) { - std::getline(fh, bit); - continue; - } - row.timestamp = atoi(bit.c_str()); - - // Get the actor - row.actor = getActorId(deSerializeJsonString(fh)); - - // Get the action type - std::getline(fh, bit, '['); - std::getline(fh, bit, ' '); - - if (bit == "modify_inventory_stack") { - row.type = RollbackAction::TYPE_MODIFY_INVENTORY_STACK; - row.location = trim(deSerializeJsonString(fh)); - std::getline(fh, bit, ' '); - row.list = trim(deSerializeJsonString(fh)); - std::getline(fh, bit, ' '); - std::getline(fh, bit, ' '); - row.index = atoi(trim(bit).c_str()); - std::getline(fh, bit, ' '); - row.add = (int)(trim(bit) == "add"); - row.stack.deSerialize(deSerializeJsonString(fh)); - row.stack.id = getNodeId(row.stack.name); - std::getline(fh, bit); - } else if (bit == "set_node") { - row.type = RollbackAction::TYPE_SET_NODE; - std::getline(fh, bit, '('); - std::getline(fh, bit, ','); - row.x = atoi(trim(bit).c_str()); - std::getline(fh, bit, ','); - row.y = atoi(trim(bit).c_str()); - std::getline(fh, bit, ')'); - row.z = atoi(trim(bit).c_str()); - std::getline(fh, bit, ' '); - row.oldNode = getNodeId(trim(deSerializeJsonString(fh))); - std::getline(fh, bit, ' '); - std::getline(fh, bit, ' '); - row.oldParam1 = atoi(trim(bit).c_str()); - std::getline(fh, bit, ' '); - row.oldParam2 = atoi(trim(bit).c_str()); - row.oldMeta = trim(deSerializeJsonString(fh)); - std::getline(fh, bit, ' '); - row.newNode = getNodeId(trim(deSerializeJsonString(fh))); - std::getline(fh, bit, ' '); - std::getline(fh, bit, ' '); - row.newParam1 = atoi(trim(bit).c_str()); - std::getline(fh, bit, ' '); - row.newParam2 = atoi(trim(bit).c_str()); - row.newMeta = trim(deSerializeJsonString(fh)); - std::getline(fh, bit, ' '); - std::getline(fh, bit, ' '); - std::getline(fh, bit); - row.guessed = (int)(trim(bit) == "actor_is_guess"); - } else { - errorstream << "Unrecognized rollback action type \"" - << bit << "\"!" << std::endl; - continue; - } - - registerRow(row); - ++i; - - if (time(0) - t >= 1) { - SQLRES(sqlite3_step(stmt_commit), SQLITE_DONE); - sqlite3_reset(stmt_commit); - t = time(0); - std::cout - << " Done: " << static_cast((static_cast(fh.tellg()) / static_cast(file_size)) * 100) << "%" - << " Speed: " << i / (t - start) << "/second \r" << std::flush; - SQLRES(sqlite3_step(stmt_begin), SQLITE_DONE); - sqlite3_reset(stmt_begin); - } - } while (fh.good()); - SQLRES(sqlite3_step(stmt_commit), SQLITE_DONE); - sqlite3_reset(stmt_commit); - - SQLOK(sqlite3_finalize(stmt_begin)); - SQLOK(sqlite3_finalize(stmt_commit)); - - std::cout - << " Done: 100% " << std::endl - << "Now you can delete the old rollback.txt file." << std::endl; -} - - // Get nearness factor for subject's action for this action // Return value: 0 = impossible, >0 = factor float RollbackManager::getSuspectNearness(bool is_guess, v3s16 suspect_p, diff --git a/src/rollback.h b/src/rollback.h index ff96e513f..b5131fa71 100644 --- a/src/rollback.h +++ b/src/rollback.h @@ -73,7 +73,6 @@ class RollbackManager: public IRollbackManager int range, int limit); const std::list getActionsSince(time_t firstTime, const std::string & actor = ""); - void migrate(const std::string & filepath); static float getSuspectNearness(bool is_guess, v3s16 suspect_p, time_t suspect_t, v3s16 action_p, time_t action_t); -- 2.44.0