diff options
Diffstat (limited to 'src/server/database/Updater/UpdateFetcher.cpp')
-rw-r--r-- | src/server/database/Updater/UpdateFetcher.cpp | 29 |
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); } |