From 4201ca021ba20349cb4ebe87582f1ad035dd7a85 Mon Sep 17 00:00:00 2001 From: Naios Date: Tue, 24 Mar 2015 12:58:55 +0100 Subject: Core/DBUpdater: Add the possibility to limit the remove of orphaned entries. * This will save you from loosing your update history if you use a repository in bad state (revision or branch) by mistake. * Also turned 1 error message into a warning (cherry picked from commit 966282fbed24a0d0cf8cb3e05b1849c3e6a0d1d6) (cherry picked from commit 3ad7776d5061308d3e2b4ff9e3cbf67d48bffdd6) --- src/server/shared/Updater/DBUpdater.cpp | 2 +- src/server/shared/Updater/UpdateFetcher.cpp | 30 +++++++++++++++++++++-------- src/server/shared/Updater/UpdateFetcher.h | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src/server/shared') diff --git a/src/server/shared/Updater/DBUpdater.cpp b/src/server/shared/Updater/DBUpdater.cpp index 3c0ad4d1476..15226577504 100644 --- a/src/server/shared/Updater/DBUpdater.cpp +++ b/src/server/shared/Updater/DBUpdater.cpp @@ -244,7 +244,7 @@ bool DBUpdater::Update(DatabaseWorkerPool& pool) sConfigMgr->GetBoolDefault("Updates.Redundancy", true), sConfigMgr->GetBoolDefault("Updates.AllowRehash", true), sConfigMgr->GetBoolDefault("Updates.ArchivedRedundancy", false), - sConfigMgr->GetBoolDefault("Updates.CleanDeadRef", true)); + sConfigMgr->GetIntDefault("Updates.CleanDeadRefMaxCount", 3)); if (!count) TC_LOG_INFO("sql.updates", ">> %s database is up-to-date!", DBUpdater::GetTableName().c_str()); diff --git a/src/server/shared/Updater/UpdateFetcher.cpp b/src/server/shared/Updater/UpdateFetcher.cpp index 63e820c3de5..b93ca614729 100644 --- a/src/server/shared/Updater/UpdateFetcher.cpp +++ b/src/server/shared/Updater/UpdateFetcher.cpp @@ -101,7 +101,7 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons if (!is_directory(p)) { - TC_LOG_ERROR("sql.updates", "DBUpdater: Given update include directory \"%s\" isn't existing, skipped!", p.generic_string().c_str()); + TC_LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"%s\" isn't existing, skipped!", p.generic_string().c_str()); continue; } @@ -154,7 +154,7 @@ UpdateFetcher::SQLUpdate UpdateFetcher::ReadSQLUpdate(boost::filesystem::path co return update; } -uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, bool const cleanDeadReferences) const +uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const { LocaleFileStorage const available = GetFileList(); AppliedFileStorage applied = ReceiveAppliedFiles(); @@ -291,14 +291,28 @@ uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash ++importedUpdates; } - for (auto const& entry : applied) + // Cleanup up orphaned entries if enabled + if (!applied.empty()) { - TC_LOG_WARN("sql.updates", ">> File \'%s\' was applied to the database but is missing in" \ - " your update directory now!%s", entry.first.c_str(), cleanDeadReferences ? " Deleting orphaned entry..." : ""); - } + bool const doCleanup = (cleanDeadReferencesMaxCount < 0) || (applied.size() <= static_cast(cleanDeadReferencesMaxCount)); + + for (auto const& entry : applied) + { + TC_LOG_WARN("sql.updates", ">> File \'%s\' was applied to the database but is missing in" \ + " your update directory now!", entry.first.c_str()); + + if (doCleanup) + TC_LOG_INFO("sql.updates", "Deleting orphaned entry \'%s\'...", entry.first.c_str()); + } - if (cleanDeadReferences) - CleanUp(applied); + if (doCleanup) + CleanUp(applied); + else + { + TC_LOG_ERROR("sql.updates", "Cleanup is disabled! There are %zu dirty files that were applied to your database " \ + "but are now missing in your source directory!", applied.size()); + } + } return importedUpdates; } diff --git a/src/server/shared/Updater/UpdateFetcher.h b/src/server/shared/Updater/UpdateFetcher.h index f545c232a94..094e353f274 100644 --- a/src/server/shared/Updater/UpdateFetcher.h +++ b/src/server/shared/Updater/UpdateFetcher.h @@ -36,7 +36,7 @@ public: std::function const& retrieve); uint32 Update(bool const redundancyChecks, bool const allowRehash, - bool const archivedRedundancy, bool const cleanDeadReferences) const; + bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const; private: enum UpdateMode -- cgit v1.2.3