aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Updater
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
committerariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
commit85a7d5ce9ac68b30da2277cc91d4b70358f1880d (patch)
treedf3d2084ee2e35008903c03178039b9c986e2d08 /src/server/database/Updater
parent052fc24315ace866ea1cf610e85df119b68100c9 (diff)
Core: ported headers cleanup from master branch
Diffstat (limited to 'src/server/database/Updater')
-rw-r--r--src/server/database/Updater/DBUpdater.cpp33
-rw-r--r--src/server/database/Updater/DBUpdater.h29
-rw-r--r--src/server/database/Updater/UpdateFetcher.cpp31
-rw-r--r--src/server/database/Updater/UpdateFetcher.h46
4 files changed, 80 insertions, 59 deletions
diff --git a/src/server/database/Updater/DBUpdater.cpp b/src/server/database/Updater/DBUpdater.cpp
index 104533c1573..b82e0919dab 100644
--- a/src/server/database/Updater/DBUpdater.cpp
+++ b/src/server/database/Updater/DBUpdater.cpp
@@ -16,17 +16,18 @@
*/
#include "DBUpdater.h"
-#include "Log.h"
-#include "GitRevision.h"
-#include "UpdateFetcher.h"
-#include "DatabaseLoader.h"
-#include "Config.h"
#include "BuiltInConfig.h"
+#include "Config.h"
+#include "DatabaseEnv.h"
+#include "DatabaseLoader.h"
+#include "GitRevision.h"
+#include "Log.h"
+#include "QueryResult.h"
#include "StartProcess.h"
-
+#include "UpdateFetcher.h"
+#include <boost/filesystem/operations.hpp>
#include <fstream>
#include <iostream>
-#include <unordered_map>
std::string DBUpdaterUtil::GetCorrectedMySQLExecutable()
{
@@ -41,18 +42,12 @@ bool DBUpdaterUtil::CheckExecutable()
boost::filesystem::path exe(GetCorrectedMySQLExecutable());
if (!exists(exe))
{
- exe.clear();
-
- if (auto path = Trinity::SearchExecutableInPath("mysql"))
+ exe = Trinity::SearchExecutableInPath("mysql");
+ if (!exe.empty() && exists(exe))
{
- exe = std::move(*path);
-
- if (!exe.empty() && exists(exe))
- {
- // Correct the path to the cli
- corrected_path() = absolute(exe).generic_string();
- return true;
- }
+ // Correct the path to the cli
+ corrected_path() = absolute(exe).generic_string();
+ return true;
}
TC_LOG_FATAL("sql.updates", "Didn't find any executable MySQL binary at \'%s\' or in path, correct the path in the *.conf (\"MySQLExecutable\").",
@@ -313,7 +308,7 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool)
template<class T>
QueryResult DBUpdater<T>::Retrieve(DatabaseWorkerPool<T>& pool, std::string const& query)
{
- return pool.PQuery(query.c_str());
+ return pool.Query(query.c_str());
}
template<class T>
diff --git a/src/server/database/Updater/DBUpdater.h b/src/server/database/Updater/DBUpdater.h
index fdc00c9d6b6..8cea468e3cd 100644
--- a/src/server/database/Updater/DBUpdater.h
+++ b/src/server/database/Updater/DBUpdater.h
@@ -18,10 +18,20 @@
#ifndef DBUpdater_h__
#define DBUpdater_h__
-#include "DatabaseEnv.h"
-
+#include "Define.h"
+#include "DatabaseEnvFwd.h"
#include <string>
-#include <boost/filesystem.hpp>
+
+template <class T>
+class DatabaseWorkerPool;
+
+namespace boost
+{
+ namespace filesystem
+ {
+ class path;
+ }
+}
class TC_DATABASE_API UpdateException : public std::exception
{
@@ -41,19 +51,6 @@ enum BaseLocation
LOCATION_DOWNLOAD
};
-struct TC_DATABASE_API UpdateResult
-{
- UpdateResult()
- : updated(0), recent(0), archived(0) { }
-
- UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
- : updated(updated_), recent(recent_), archived(archived_) { }
-
- size_t updated;
- size_t recent;
- size_t archived;
-};
-
class DBUpdaterUtil
{
public:
diff --git a/src/server/database/Updater/UpdateFetcher.cpp b/src/server/database/Updater/UpdateFetcher.cpp
index 1da370ee7b9..4f12f6c09cd 100644
--- a/src/server/database/Updater/UpdateFetcher.cpp
+++ b/src/server/database/Updater/UpdateFetcher.cpp
@@ -16,28 +16,40 @@
*/
#include "UpdateFetcher.h"
+#include "Common.h"
+#include "DBUpdater.h"
+#include "Field.h"
#include "Log.h"
+#include "QueryResult.h"
#include "Util.h"
#include "SHA1.h"
-
+#include <boost/filesystem/operations.hpp>
#include <fstream>
-#include <chrono>
-#include <vector>
#include <sstream>
-#include <exception>
-#include <unordered_map>
using namespace boost::filesystem;
+struct UpdateFetcher::DirectoryEntry
+{
+ DirectoryEntry(Path const& path_, State state_) : path(path_), state(state_) { }
+
+ Path const path;
+ State const state;
+};
+
UpdateFetcher::UpdateFetcher(Path const& sourceDirectory,
std::function<void(std::string const&)> const& apply,
std::function<void(Path const& path)> const& applyFile,
std::function<QueryResult(std::string const&)> const& retrieve) :
- _sourceDirectory(sourceDirectory), _apply(apply), _applyFile(applyFile),
+ _sourceDirectory(Trinity::make_unique<Path>(sourceDirectory)), _apply(apply), _applyFile(applyFile),
_retrieve(retrieve)
{
}
+UpdateFetcher::~UpdateFetcher()
+{
+}
+
UpdateFetcher::LocaleFileStorage UpdateFetcher::GetFileList() const
{
LocaleFileStorage files;
@@ -95,7 +107,7 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
std::string path = fields[0].GetString();
if (path.substr(0, 1) == "$")
- path = _sourceDirectory.generic_string() + path.substr(1);
+ path = _sourceDirectory->generic_string() + path.substr(1);
Path const p(path);
@@ -405,3 +417,8 @@ void UpdateFetcher::UpdateState(std::string const& name, State const state) cons
// Update database
_apply(update);
}
+
+bool UpdateFetcher::PathCompare::operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const
+{
+ return left.first.filename().string() < right.first.filename().string();
+}
diff --git a/src/server/database/Updater/UpdateFetcher.h b/src/server/database/Updater/UpdateFetcher.h
index 51f735e797f..a905e21dcd3 100644
--- a/src/server/database/Updater/UpdateFetcher.h
+++ b/src/server/database/Updater/UpdateFetcher.h
@@ -18,13 +18,34 @@
#ifndef UpdateFetcher_h__
#define UpdateFetcher_h__
-#include <DBUpdater.h>
-
-#include <functional>
+#include "Define.h"
+#include "DatabaseEnvFwd.h"
+#include <set>
#include <string>
-#include <memory>
+#include <unordered_map>
#include <vector>
+namespace boost
+{
+ namespace filesystem
+ {
+ class path;
+ }
+}
+
+struct TC_DATABASE_API UpdateResult
+{
+ UpdateResult()
+ : updated(0), recent(0), archived(0) { }
+
+ UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
+ : updated(updated_), recent(recent_), archived(archived_) { }
+
+ size_t updated;
+ size_t recent;
+ size_t archived;
+};
+
class TC_DATABASE_API UpdateFetcher
{
typedef boost::filesystem::path Path;
@@ -34,6 +55,7 @@ public:
std::function<void(std::string const&)> const& apply,
std::function<void(Path const& path)> const& applyFile,
std::function<QueryResult(std::string const&)> const& retrieve);
+ ~UpdateFetcher();
UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const;
@@ -80,23 +102,13 @@ private:
}
};
- struct DirectoryEntry
- {
- DirectoryEntry(Path const& path_, State state_) : path(path_), state(state_) { }
-
- Path const path;
-
- State const state;
- };
+ struct DirectoryEntry;
typedef std::pair<Path, State> LocaleFileEntry;
struct PathCompare
{
- inline bool operator() (LocaleFileEntry const& left, LocaleFileEntry const& right) const
- {
- return left.first.filename().string() < right.first.filename().string();
- }
+ bool operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const;
};
typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;
@@ -121,7 +133,7 @@ private:
void UpdateState(std::string const& name, State const state) const;
- Path const _sourceDirectory;
+ std::unique_ptr<Path> const _sourceDirectory;
std::function<void(std::string const&)> const _apply;
std::function<void(Path const& path)> const _applyFile;