diff options
author | Naios <naios-dev@live.de> | 2015-10-01 16:45:26 +0200 |
---|---|---|
committer | Naios <naios-dev@live.de> | 2015-10-05 17:11:59 +0200 |
commit | a561edefb90af25864aeb7ca7fc48fe0364df765 (patch) | |
tree | 38669bdb86e871fac6503902d92a17c236ecb766 | |
parent | 0cf04cc166e4bd79c1e1f5ceb636d31bf8af560a (diff) |
Core/Updater: Fix mysql in path check/search.
-rw-r--r-- | src/server/database/Updater/DBUpdater.cpp | 96 | ||||
-rw-r--r-- | src/server/database/Updater/DBUpdater.h | 14 |
2 files changed, 64 insertions, 46 deletions
diff --git a/src/server/database/Updater/DBUpdater.cpp b/src/server/database/Updater/DBUpdater.cpp index c9056e12361..354315ec782 100644 --- a/src/server/database/Updater/DBUpdater.cpp +++ b/src/server/database/Updater/DBUpdater.cpp @@ -35,24 +35,64 @@ using namespace boost::process; using namespace boost::process::initializers; using namespace boost::iostreams; -template<class T> -std::string DBUpdater<T>::GetSourceDirectory() +std::string DBUpdaterUtil::GetMySqlCli() { - std::string const entry = sConfigMgr->GetStringDefault("Updates.SourcePath", ""); - if (!entry.empty()) - return entry; + if (!corrected_path().empty()) + return corrected_path(); else - return GitRevision::GetSourceDirectory(); + { + std::string const entry = sConfigMgr->GetStringDefault("Updates.MySqlCLIPath", ""); + if (!entry.empty()) + return entry; + else + return GitRevision::GetMySQLExecutable(); + } +} + +bool DBUpdaterUtil::CheckExecutable() +{ + boost::filesystem::path exe(GetMySqlCli()); + if (!exists(exe)) + { + exe.clear(); + + try + { + exe = search_path("mysql"); + } + catch (std::runtime_error&) + { + } + + if (!exe.empty() && exists(exe)) + { + // Correct the path to the cli + corrected_path() = absolute(exe).generic_string(); + return true; + } + + TC_LOG_FATAL("sql.updates", "Didn't find executeable mysql binary at \'%s\' or in path, correct the path in the *.conf (\"Updates.MySqlCLIPath\").", + absolute(exe).generic_string().c_str()); + + return false; + } + return true; +} + +std::string& DBUpdaterUtil::corrected_path() +{ + static std::string path; + return path; } template<class T> -std::string DBUpdater<T>::GetMySqlCli() +std::string DBUpdater<T>::GetSourceDirectory() { - std::string const entry = sConfigMgr->GetStringDefault("Updates.MySqlCLIPath", ""); + std::string const entry = sConfigMgr->GetStringDefault("Updates.SourcePath", ""); if (!entry.empty()) return entry; else - return GitRevision::GetMySQLExecutable(); + return GitRevision::GetSourceDirectory(); } // Auth Database @@ -147,36 +187,6 @@ BaseLocation DBUpdater<T>::GetBaseLocationType() } template<class T> -bool DBUpdater<T>::CheckExecutable() -{ - DBUpdater<T>::Path const exe(DBUpdater<T>::GetMySqlCli()); - if (!exists(exe)) - { - // Check for mysql in path - std::vector<std::string> args = {"--version"}; - uint32 ret; - try - { - child c = execute(run_exe("mysql"), set_args(args), throw_on_error(), close_stdout()); - ret = wait_for_exit(c); - } - catch (boost::system::system_error&) - { - ret = EXIT_FAILURE; - } - - if (ret == EXIT_FAILURE) - { - TC_LOG_FATAL("sql.updates", "Didn't find executeable mysql binary at \'%s\', correct the path in the *.conf (\"Updates.MySqlCLIPath\").", - absolute(exe).generic_string().c_str()); - - return false; - } - } - return true; -} - -template<class T> bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool) { TC_LOG_INFO("sql.updates", "Database \"%s\" does not exist, do you want to create it? [yes (default) / no]: ", @@ -224,7 +234,7 @@ bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool) template<class T> bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool) { - if (!DBUpdater<T>::CheckExecutable()) + if (!DBUpdaterUtil::CheckExecutable()) return false; TC_LOG_INFO("sql.updates", "Updating %s database...", DBUpdater<T>::GetTableName().c_str()); @@ -275,7 +285,7 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool) return true; } - if (!DBUpdater<T>::CheckExecutable()) + if (!DBUpdaterUtil::CheckExecutable()) return false; TC_LOG_INFO("sql.updates", "Database %s is empty, auto populating it...", DBUpdater<T>::GetTableName().c_str()); @@ -396,8 +406,8 @@ void DBUpdater<T>::ApplyFile(DatabaseWorkerPool<T>& pool, std::string const& hos boost::process::pipe outPipe = create_pipe(); boost::process::pipe errPipe = create_pipe(); - child c = execute(run_exe(DBUpdater<T>::GetMySqlCli().empty() ? "mysql" : - boost::filesystem::absolute(DBUpdater<T>::GetMySqlCli()).generic_string()), + child c = execute(run_exe( + boost::filesystem::absolute(DBUpdaterUtil::GetMySqlCli()).generic_string()), set_args(args), bind_stdin(source), throw_on_error(), bind_stdout(file_descriptor_sink(outPipe.sink, close_handle)), bind_stderr(file_descriptor_sink(errPipe.sink, close_handle))); diff --git a/src/server/database/Updater/DBUpdater.h b/src/server/database/Updater/DBUpdater.h index a2b12bed235..c8aa5d69fbc 100644 --- a/src/server/database/Updater/DBUpdater.h +++ b/src/server/database/Updater/DBUpdater.h @@ -54,6 +54,17 @@ struct UpdateResult size_t archived; }; +class DBUpdaterUtil +{ +public: + static std::string GetMySqlCli(); + + static bool CheckExecutable(); + +private: + static std::string& corrected_path(); +}; + template <class T> class DBUpdater { @@ -79,9 +90,6 @@ public: static bool Populate(DatabaseWorkerPool<T>& pool); private: - static std::string GetMySqlCli(); - static bool CheckExecutable(); - static QueryResult Retrieve(DatabaseWorkerPool<T>& pool, std::string const& query); static void Apply(DatabaseWorkerPool<T>& pool, std::string const& query); static void ApplyFile(DatabaseWorkerPool<T>& pool, Path const& path); |