logic: fixed passing non-ascii characters to indexer process via command-line
This commit is contained in:
@@ -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> fileLogger = std::make_shared<FileLogger>();
|
||||
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<IndexerFactoryModuleJava>());
|
||||
IndexerFactory::getInstance()->addModule(std::make_shared<IndexerFactoryModuleCxxCdb>());
|
||||
|
||||
@@ -52,11 +52,11 @@ void TaskBuildIndex::doEnter(std::shared_ptr<Blackboard> 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<FileLogger*>(logger)->getLogFilePath().str();
|
||||
logFilePath = dynamic_cast<FileLogger*>(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<std::mutex> 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<std::wstring> 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));
|
||||
}
|
||||
|
||||
@@ -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> blackboard);
|
||||
void updateIndexingDialog(std::shared_ptr<Blackboard> blackboard, const std::vector<FilePath>& sourcePaths);
|
||||
|
||||
@@ -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<std::wstring>& 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<std::mutex> lock(s_runningProcessesMutex);
|
||||
process.start(command.c_str());
|
||||
process.start(command);
|
||||
s_runningProcesses.insert(&process);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::wstring>& commandArguments,
|
||||
const FilePath& workingDirectory = FilePath(),
|
||||
const int timeout = 30000
|
||||
);
|
||||
|
||||
void killRunningProcesses();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user