logic: fix qprocess stuck if finished or errored too quickly
This commit is contained in:
@@ -147,11 +147,14 @@ int utility::executeProcessAndGetExitCode(
|
||||
bool logProcessOutput,
|
||||
std::wstring* errorMessage
|
||||
){
|
||||
bool finished = false;
|
||||
|
||||
QProcess process;
|
||||
|
||||
if (errorMessage != nullptr)
|
||||
QObject::connect(&process, &QProcess::errorOccurred, [&finished, errorMessage, commandPath](QProcess::ProcessError error)
|
||||
{
|
||||
QObject::connect(&process, &QProcess::errorOccurred, [errorMessage, commandPath](QProcess::ProcessError error)
|
||||
finished = true;
|
||||
if (errorMessage != nullptr)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
@@ -173,9 +176,15 @@ int utility::executeProcessAndGetExitCode(
|
||||
case QProcess::UnknownError:
|
||||
*errorMessage = L"An unknown error occurred while executing process.";
|
||||
break;
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
QObject::connect(&process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [&finished](int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
finished = true;
|
||||
});
|
||||
|
||||
|
||||
if (!workingDirectory.empty())
|
||||
{
|
||||
@@ -204,7 +213,7 @@ int utility::executeProcessAndGetExitCode(
|
||||
std::wstring errorBuffer;
|
||||
if (timeout == -1)
|
||||
{
|
||||
while (!process.waitForFinished(1000))
|
||||
while (!finished && process.waitForFinished(1000))
|
||||
{
|
||||
if (logProcessOutput)
|
||||
{
|
||||
@@ -214,7 +223,10 @@ int utility::executeProcessAndGetExitCode(
|
||||
}
|
||||
else
|
||||
{
|
||||
process.waitForFinished(timeout);
|
||||
if (!finished)
|
||||
{
|
||||
process.waitForFinished(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (logProcessOutput)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef FOO_H
|
||||
#define FOO_H
|
||||
#ifndef BAR_H
|
||||
#define BAR_H
|
||||
|
||||
#include "FooBar.h"
|
||||
|
||||
@@ -7,4 +7,4 @@ class Bar : public FooBar
|
||||
{
|
||||
};
|
||||
|
||||
#endif // FOO_H
|
||||
#endif // BAR_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef BAR_H
|
||||
#define BAR_H
|
||||
#ifndef FOO_H
|
||||
#define FOO_H
|
||||
|
||||
#include "FooBar.h"
|
||||
|
||||
@@ -7,4 +7,4 @@ class Foo : public FooBar
|
||||
{
|
||||
};
|
||||
|
||||
#endif // FOO_BAR_H
|
||||
#endif // FOO_H
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* Click "Add Source Group"
|
||||
* Select "Custom" -> "Custom Command Source Group"
|
||||
* Click "Next"
|
||||
* Add "python <path/to/working_copy>/SourcetrailPythonIndexer/run.py --source-file-path=%{SOURCE_FILE_PATH} --database-file-path=%{DATABASE_FILE_PATH}" to "Custom Command"
|
||||
* Add "python <path/to/working_copy>/SourcetrailPythonIndexer/run.py index --source-file-path=%{SOURCE_FILE_PATH} --database-file-path=%{DATABASE_FILE_PATH}" to "Custom Command"
|
||||
* Add "./src" to "Files & Directories to Index"
|
||||
* Add "**main*" to "Excluded Files & Directories"
|
||||
* Add ".py" to "Source File Extensions"
|
||||
@@ -34,7 +34,7 @@
|
||||
* Click "Save"
|
||||
* Validate a project-file-was-changed-notification appears
|
||||
* Click "Reindex"
|
||||
* Validate "Updated files" is selected
|
||||
* Validate "All files" is selected
|
||||
* Validate "source files to index" shows "3"
|
||||
* Click "Updated files"
|
||||
* Validate "source files to index" shows "1"
|
||||
@@ -43,7 +43,9 @@
|
||||
* Click "OK"
|
||||
* Validate content of code and graph view changed and display calls from "main"
|
||||
* Run "2_update.sh"
|
||||
* Click "Refresh" button
|
||||
* Validate "Updated files" is selected
|
||||
* Validate "files to clear" shows "1"
|
||||
* Validate "source files to index" shows "1"
|
||||
* Click Start
|
||||
* Validate a dialog appears that states that the project cannot be partially cleared
|
||||
@@ -57,7 +59,8 @@
|
||||
* Validate "Warning appears that %{SOURCE_FILE_PATH} is not defined in command"
|
||||
* In "Custom Command" replace "foo" with "%{SOURCE_FILE_PATH}"
|
||||
* Click "Save"
|
||||
* Click "Refresh" button
|
||||
* Validate a project-file-was-changed-notification appears
|
||||
* Click "Reindex"
|
||||
* Click "Start"
|
||||
* Validate "Log View appears showing errors that command execution failed".
|
||||
* Close Sourcetrail
|
||||
|
||||
Reference in New Issue
Block a user