aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Updater/UpdateFetcher.cpp
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2016-02-21 03:30:47 +0100
committerNaios <naios-dev@live.de>2016-02-22 16:01:27 +0100
commitf2233f5d1426d12d16178eced900c1be9666983f (patch)
tree8db6aa0da12c3861ac0d0a3ec7aec4bea59b3fc1 /src/server/database/Updater/UpdateFetcher.cpp
parentc14ef8852285e71b4e1b9ddba438c9917add9a2a (diff)
Core/Updater: Convert an assertion into a fatal error
* The error is triggered when it fails to open an update for hashing * See 'https://community.trinitycore.org/topic/12352-worldserver-crashes-on-database-update/' for details * And a minor cleanup in the UpdateFetcher (cherry picked from commit c43b80866593af3e9743fb55a395508c7dfb5d71)
Diffstat (limited to 'src/server/database/Updater/UpdateFetcher.cpp')
-rw-r--r--src/server/database/Updater/UpdateFetcher.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/server/database/Updater/UpdateFetcher.cpp b/src/server/database/Updater/UpdateFetcher.cpp
index 001fdf20610..2d60cdb92ef 100644
--- a/src/server/database/Updater/UpdateFetcher.cpp
+++ b/src/server/database/Updater/UpdateFetcher.cpp
@@ -137,22 +137,33 @@ UpdateFetcher::AppliedFileStorage UpdateFetcher::ReceiveAppliedFiles() const
return map;
}
-UpdateFetcher::SQLUpdate UpdateFetcher::ReadSQLUpdate(boost::filesystem::path const& file) const
+std::string UpdateFetcher::ReadSQLUpdate(boost::filesystem::path const& file) const
{
std::ifstream in(file.c_str());
- WPFatal(in.is_open(), "Could not read an update file.");
+ if (!in.is_open())
+ {
+ TC_LOG_FATAL("sql.updates", "Failed to open the sql update \"%s\" for reading! "
+ "Stopping the server to keep the database integrity, "
+ "try to identify and solve the issue or disabled the database updater.",
+ file.generic_string().c_str());
+
+ throw UpdateException("Opening the sql update failed!");
+ }
auto update = [&in] {
std::ostringstream ss;
ss << in.rdbuf();
- return Trinity::make_unique<std::string>(ss.str());
+ return ss.str();
}();
in.close();
return update;
}
-UpdateResult UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const
+UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
+ bool const allowRehash,
+ bool const archivedRedundancy,
+ int32 const cleanDeadReferencesMaxCount) const
{
LocaleFileStorage const available = GetFileList();
AppliedFileStorage applied = ReceiveAppliedFiles();
@@ -198,11 +209,9 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, bool const allow
}
}
- // Read update from file
- SQLUpdate const update = ReadSQLUpdate(availableQuery.first);
-
// Calculate hash
- std::string const hash = CalculateHash(update);
+ std::string const hash =
+ CalculateHash(ReadSQLUpdate(availableQuery.first));
UpdateMode mode = MODE_APPLY;
@@ -325,11 +334,11 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks, bool const allow
return UpdateResult(importedUpdates, countRecentUpdates, countArchivedUpdates);
}
-std::string UpdateFetcher::CalculateHash(SQLUpdate const& query) const
+std::string UpdateFetcher::CalculateHash(std::string const& query) const
{
// Calculate a Sha1 hash based on query content.
unsigned char digest[SHA_DIGEST_LENGTH];
- SHA1((unsigned char*)query->c_str(), query->length(), (unsigned char*)&digest);
+ SHA1((unsigned char*)query.c_str(), query.length(), (unsigned char*)&digest);
return ByteArrayToHexStr(digest, SHA_DIGEST_LENGTH);
}