From 90efb11775d6558fcb274ad3c21c509a952eeedb Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 20 Feb 2018 17:02:50 +0100 Subject: [PATCH] logic: fixed passing non-ascii characters to indexer process via command-line --- src/indexer/main.cpp | 14 +++++++++----- src/lib/data/indexer/TaskBuildIndex.cpp | 23 ++++++++++++----------- src/lib/data/indexer/TaskBuildIndex.h | 2 +- src/lib_gui/utility/utilityApp.cpp | 16 +++++++++++++--- src/lib_gui/utility/utilityApp.h | 7 ++++++- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/indexer/main.cpp b/src/indexer/main.cpp index 46532b87..f3277215 100644 --- a/src/indexer/main.cpp +++ b/src/indexer/main.cpp @@ -14,7 +14,7 @@ #include "utility/logging/logging.h" #include "utility/logging/LogManager.h" -void setupLogging(const std::string logFilePath) +void setupLogging(const FilePath& logFilePath) { LogManager* logManager = LogManager::getInstance().get(); @@ -24,7 +24,7 @@ void setupLogging(const std::string logFilePath) logManager->addLogger(consoleLogger); std::shared_ptr fileLogger = std::make_shared(); - fileLogger->setLogFilePath(FilePath(logFilePath)); + fileLogger->setLogFilePath(logFilePath); fileLogger->setLogLevel(Logger::LOG_ALL); logManager->addLogger(fileLogger); } @@ -74,15 +74,19 @@ int main(int argc, char *argv[]) AppPath::setAppPath(FilePath(appPath)); UserPaths::setUserDataPath(FilePath(userDataPath)); - setupLogging(logFilePath); + if (!logFilePath.empty()) + { + setupLogging(FilePath(logFilePath)); + } + suppressCrashMessage(); ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); appSettings->load(FilePath(UserPaths::getAppSettingsPath())); LogManager::getInstance()->setLoggingEnabled(appSettings->getLoggingEnabled()); - LOG_INFO("appPath: " + appPath); - LOG_INFO("userDataPath: " + userDataPath); + LOG_INFO(L"appPath: " + AppPath::getAppPath().wstr()); + LOG_INFO(L"userDataPath: " + UserPaths::getUserDataPath().wstr()); IndexerFactory::getInstance()->addModule(std::make_shared()); IndexerFactory::getInstance()->addModule(std::make_shared()); diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index 6a8a5533..e0cea033 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -52,11 +52,11 @@ void TaskBuildIndex::doEnter(std::shared_ptr blackboard) m_lastCommandCount = m_indexerCommandList->size(); m_interprocessIndexerCommandManager.setIndexerCommands(m_indexerCommandList->getAllCommands()); - std::string logFilePath; + std::wstring logFilePath; Logger* logger = LogManager::getInstance()->getLoggerByType("FileLogger"); if (logger) { - logFilePath = dynamic_cast(logger)->getLogFilePath().str(); + logFilePath = dynamic_cast(logger)->getLogFilePath().wstr(); } // start indexer processes @@ -170,7 +170,7 @@ void TaskBuildIndex::handleMessage(MessageInterruptTasks* message) m_interrupted = true; } -void TaskBuildIndex::runIndexerProcess(int processId, const std::string& logFilePath) +void TaskBuildIndex::runIndexerProcess(int processId, const std::wstring& logFilePath) { { std::lock_guard lock(m_runningThreadCountMutex); @@ -185,21 +185,22 @@ void TaskBuildIndex::runIndexerProcess(int processId, const std::string& logFile return; } - std::string command = "\"" + indexerProcessPath.str() + "\""; - command += " " + std::to_string(processId); - command += " " + Application::getUUID(); - command += " \"" + AppPath::getAppPath().str() + "\""; - command += " \"" + UserPaths::getUserDataPath().str() + "\""; + const std::wstring commandPath = L"\"" + indexerProcessPath.wstr() + L"\""; + std::vector commandArguments; + commandArguments.push_back(std::to_wstring(processId)); + commandArguments.push_back(utility::decodeFromUtf8(Application::getUUID())); + commandArguments.push_back(L"\"" + AppPath::getAppPath().wstr() + L"\""); + commandArguments.push_back(L"\"" + UserPaths::getUserDataPath().wstr() + L"\""); - if (logFilePath.size()) + if (!logFilePath.empty()) { - command += " \"" + logFilePath + "\""; + commandArguments.push_back(L"\"" + logFilePath + L"\""); } int result = 1; while (result != 0 && !m_interrupted) { - result = utility::executeProcessAndGetExitCode(command.c_str(), FilePath(), -1); + result = utility::executeProcessAndGetExitCode(commandPath, commandArguments, FilePath(), -1); LOG_INFO_STREAM(<< "Indexer process " << processId << " returned with " + std::to_string(result)); } diff --git a/src/lib/data/indexer/TaskBuildIndex.h b/src/lib/data/indexer/TaskBuildIndex.h index a3cb9887..67d69d39 100644 --- a/src/lib/data/indexer/TaskBuildIndex.h +++ b/src/lib/data/indexer/TaskBuildIndex.h @@ -36,7 +36,7 @@ protected: virtual void handleMessage(MessageInterruptTasks* message); - void runIndexerProcess( int processId, const std::string& logFilePath); + void runIndexerProcess(int processId, const std::wstring& logFilePath); void runIndexerThread(int processId); bool fetchIntermediateStorages(std::shared_ptr blackboard); void updateIndexingDialog(std::shared_ptr blackboard, const std::vector& sourcePaths); diff --git a/src/lib_gui/utility/utilityApp.cpp b/src/lib_gui/utility/utilityApp.cpp index 0fb6bd02..4d3983f8 100644 --- a/src/lib_gui/utility/utilityApp.cpp +++ b/src/lib_gui/utility/utilityApp.cpp @@ -92,8 +92,12 @@ std::string utility::executeProcessUntilNoOutput(const std::string& command, con return processoutput; } -int utility::executeProcessAndGetExitCode(const std::string& command, const FilePath& workingDirectory, const int timeout) -{ +int utility::executeProcessAndGetExitCode( + const std::wstring& commandPath, + const std::vector& commandArguments, + const FilePath& workingDirectory, + const int timeout +){ QProcess process; if (!workingDirectory.empty()) @@ -101,9 +105,15 @@ int utility::executeProcessAndGetExitCode(const std::string& command, const File process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr())); } + QString command = QString::fromStdWString(commandPath); + for (const std::wstring& commandArgument : commandArguments) + { + command += " " + QString::fromStdWString(commandArgument); + } + { std::lock_guard lock(s_runningProcessesMutex); - process.start(command.c_str()); + process.start(command); s_runningProcesses.insert(&process); } diff --git a/src/lib_gui/utility/utilityApp.h b/src/lib_gui/utility/utilityApp.h index 051a06a2..a320c3a8 100644 --- a/src/lib_gui/utility/utilityApp.h +++ b/src/lib_gui/utility/utilityApp.h @@ -14,7 +14,12 @@ namespace utility { std::string executeProcess(const std::string& command, const FilePath& workingDirectory = FilePath(), const int timeout = 30000); std::string executeProcessUntilNoOutput(const std::string& command, const FilePath& workingDirectory, int waitTime = 10000); - int executeProcessAndGetExitCode(const std::string& command, const FilePath& workingDirectory = FilePath(), const int timeout = 30000); + int executeProcessAndGetExitCode( + const std::wstring& commandPath, + const std::vector& commandArguments, + const FilePath& workingDirectory = FilePath(), + const int timeout = 30000 + ); void killRunningProcesses();