171 size_t countRecentUpdates = 0;
172 size_t countArchivedUpdates = 0;
175 for (
auto const& entry : applied)
177 ++countRecentUpdates;
179 ++countArchivedUpdates;
183 for (
auto entry : applied)
184 hashToName.insert(std::make_pair(entry.second.hash, entry.first));
186 size_t importedUpdates = 0;
188 for (
auto const& availableQuery : available)
190 TC_LOG_DEBUG(
"sql.updates",
"Checking update \"%s\"...", availableQuery.first.filename().generic_string().c_str());
192 AppliedFileStorage::const_iterator iter = applied.find(availableQuery.first.filename().string());
193 if (iter != applied.end())
196 if (!redundancyChecks)
198 TC_LOG_DEBUG(
"sql.updates",
">> Update is already applied, skipping redundancy checks.");
204 if (!archivedRedundancy && (iter->second.state ==
ARCHIVED) && (availableQuery.second ==
ARCHIVED))
206 TC_LOG_DEBUG(
"sql.updates",
">> Update is archived and marked as archived in database, skipping redundancy checks.");
213 std::string
const hash =
219 if (iter == applied.end())
222 HashToFileNameStorage::const_iterator
const hashIter = hashToName.find(hash);
223 if (hashIter != hashToName.end())
226 LocaleFileStorage::const_iterator localeIter;
228 for (localeIter = available.begin(); (localeIter != available.end()) &&
229 (localeIter->first.filename().string() != hashIter->second); ++localeIter);
232 if (localeIter != available.end())
234 TC_LOG_WARN(
"sql.updates",
">> Seems like update \"%s\" \'%s\' was renamed, but the old file is still there! " \
235 "Trade it as a new file! (Probably its an unmodified copy of file \"%s\")",
236 availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str(),
237 localeIter->first.filename().string().c_str());
242 TC_LOG_INFO(
"sql.updates",
">> Renaming update \"%s\" to \"%s\" \'%s\'.",
243 hashIter->second.c_str(), availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str());
245 RenameEntry(hashIter->second, availableQuery.first.filename().string());
246 applied.erase(hashIter->second);
253 TC_LOG_INFO(
"sql.updates",
">> Applying update \"%s\" \'%s\'...",
254 availableQuery.first.filename().string().c_str(), hash.substr(0, 7).c_str());
258 else if (allowRehash && iter->second.hash.empty())
262 TC_LOG_INFO(
"sql.updates",
">> Re-hashing update \"%s\" \'%s\'...", availableQuery.first.filename().string().c_str(),
263 hash.substr(0, 7).c_str());
268 if (iter->second.hash != hash)
270 TC_LOG_INFO(
"sql.updates",
">> Reapplying update \"%s\" \'%s\' -> \'%s\' (it changed)...", availableQuery.first.filename().string().c_str(),
271 iter->second.hash.substr(0, 7).c_str(), hash.substr(0, 7).c_str());
276 if (iter->second.state != availableQuery.second)
278 TC_LOG_DEBUG(
"sql.updates",
">> Updating state of \"%s\" to \'%s\'...",
281 UpdateState(availableQuery.first.filename().string(), availableQuery.second);
284 TC_LOG_DEBUG(
"sql.updates",
">> Update is already applied and is matching hash \'%s\'.", hash.substr(0, 7).c_str());
292 AppliedFileEntry
const file = { availableQuery.first.filename().string(),
hash, availableQuery.second, 0 };
297 speed =
Apply(availableQuery.first);
304 if (iter != applied.end())
312 if (!applied.empty())
314 bool const doCleanup = (cleanDeadReferencesMaxCount < 0) || (applied.size() <=
static_cast<size_t>(cleanDeadReferencesMaxCount));
316 for (
auto const& entry : applied)
318 TC_LOG_WARN(
"sql.updates",
">> File \'%s\' was applied to the database but is missing in" \
319 " your update directory now!", entry.first.c_str());
322 TC_LOG_INFO(
"sql.updates",
"Deleting orphaned entry \'%s\'...", entry.first.c_str());
329 TC_LOG_ERROR(
"sql.updates",
"Cleanup is disabled! There are " SZFMTD " dirty files that were applied to your database " \
330 "but are now missing in your source directory!", applied.size());
334 return UpdateResult(importedUpdates, countRecentUpdates, countArchivedUpdates);
std::string ReadSQLUpdate(Path const &file) const
Definition: UpdateFetcher.cpp:140
std::string CalculateHash(std::string const &query) const
Definition: UpdateFetcher.cpp:337
#define hash
Definition: private_namespace.h:186
#define SZFMTD
Definition: Define.h:143
static State StateConvert(std::string const &state)
Definition: UpdateFetcher.h:67
Definition: UpdateFetcher.h:51
LocaleFileStorage GetFileList() const
Definition: UpdateFetcher.cpp:41
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: UpdateFetcher.h:50
uint32 Apply(Path const &path) const
Definition: UpdateFetcher.cpp:346
std::set< LocaleFileEntry, PathCompare > LocaleFileStorage
Definition: UpdateFetcher.h:102
Definition: DBUpdater.h:44
std::unordered_map< std::string, std::string > HashToFileNameStorage
Definition: UpdateFetcher.h:103
Definition: UpdateFetcher.h:45
void UpdateEntry(AppliedFileEntry const &entry, uint32 const speed=0) const
Definition: UpdateFetcher.cpp:360
uint32_t uint32
Definition: Define.h:150
std::unordered_map< std::string, AppliedFileEntry > AppliedFileStorage
Definition: UpdateFetcher.h:104
Definition: UpdateFetcher.h:44
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
AppliedFileStorage ReceiveAppliedFiles() const
Definition: UpdateFetcher.cpp:118
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
void CleanUp(AppliedFileStorage const &storage) const
Definition: UpdateFetcher.cpp:388
void UpdateState(std::string const &name, State const state) const
Definition: UpdateFetcher.cpp:411
UpdateMode
Definition: UpdateFetcher.h:42
void RenameEntry(std::string const &from, std::string const &to) const
Definition: UpdateFetcher.cpp:369