From a561edefb90af25864aeb7ca7fc48fe0364df765 Mon Sep 17 00:00:00 2001 From: Naios Date: Thu, 1 Oct 2015 16:45:26 +0200 Subject: Core/Updater: Fix mysql in path check/search. --- src/server/database/Updater/DBUpdater.cpp | 96 +++++++++++++++++-------------- 1 file changed, 53 insertions(+), 43 deletions(-) (limited to 'src/server/database/Updater/DBUpdater.cpp') 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 -std::string DBUpdater::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 -std::string DBUpdater::GetMySqlCli() +std::string DBUpdater::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 @@ -146,36 +186,6 @@ BaseLocation DBUpdater::GetBaseLocationType() return LOCATION_REPOSITORY; } -template -bool DBUpdater::CheckExecutable() -{ - DBUpdater::Path const exe(DBUpdater::GetMySqlCli()); - if (!exists(exe)) - { - // Check for mysql in path - std::vector 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 bool DBUpdater::Create(DatabaseWorkerPool& pool) { @@ -224,7 +234,7 @@ bool DBUpdater::Create(DatabaseWorkerPool& pool) template bool DBUpdater::Update(DatabaseWorkerPool& pool) { - if (!DBUpdater::CheckExecutable()) + if (!DBUpdaterUtil::CheckExecutable()) return false; TC_LOG_INFO("sql.updates", "Updating %s database...", DBUpdater::GetTableName().c_str()); @@ -275,7 +285,7 @@ bool DBUpdater::Populate(DatabaseWorkerPool& pool) return true; } - if (!DBUpdater::CheckExecutable()) + if (!DBUpdaterUtil::CheckExecutable()) return false; TC_LOG_INFO("sql.updates", "Database %s is empty, auto populating it...", DBUpdater::GetTableName().c_str()); @@ -396,8 +406,8 @@ void DBUpdater::ApplyFile(DatabaseWorkerPool& pool, std::string const& hos boost::process::pipe outPipe = create_pipe(); boost::process::pipe errPipe = create_pipe(); - child c = execute(run_exe(DBUpdater::GetMySqlCli().empty() ? "mysql" : - boost::filesystem::absolute(DBUpdater::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))); -- cgit v1.2.3