mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user