Utils: Remove SynchronousProcess::readDataFromProcess helper

QtcProcess can do that nowadays.

Change-Id: Ic3b08146263da2eb189f043eb743c621c18b82c8
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-04 07:49:33 +02:00
parent 9c3420120e
commit e10b5a4dbb
3 changed files with 5 additions and 54 deletions

View File

@@ -1324,6 +1324,11 @@ static bool askToKill(const QString &command)
#endif
}
// Helper for running a process synchronously in the foreground with timeout
// detection similar SynchronousProcess' handling (taking effect after no more output
// occurs on stderr/stdout as opposed to waitForFinished()). Returns false if a timeout
// occurs. Checking of the process' exit state/code still has to be done.
bool QtcProcess::readDataFromProcess(int timeoutS,
QByteArray *stdOut,
QByteArray *stdErr,

View File

@@ -645,50 +645,6 @@ QSharedPointer<QProcess> SynchronousProcess::createProcess(unsigned flags)
return QSharedPointer<QProcess>(process);
}
// Static utilities: Keep running as long as it gets data.
bool SynchronousProcess::readDataFromProcess(QProcess &p, int timeoutS,
QByteArray *stdOut, QByteArray *stdErr,
bool showTimeOutMessageBox)
{
if (syncDebug)
qDebug() << ">readDataFromProcess" << timeoutS;
if (p.state() != QProcess::Running) {
qWarning("readDataFromProcess: Process in non-running state passed in.");
return false;
}
QTC_ASSERT(p.readChannel() == QProcess::StandardOutput, return false);
// Keep the process running until it has no longer has data
bool finished = false;
bool hasData = false;
do {
finished = p.waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1)
|| p.state() == QProcess::NotRunning;
// First check 'stdout'
if (p.bytesAvailable()) { // applies to readChannel() only
hasData = true;
const QByteArray newStdOut = p.readAllStandardOutput();
if (stdOut)
stdOut->append(newStdOut);
}
// Check 'stderr' separately. This is a special handling
// for 'git pull' and the like which prints its progress on stderr.
const QByteArray newStdErr = p.readAllStandardError();
if (!newStdErr.isEmpty()) {
hasData = true;
if (stdErr)
stdErr->append(newStdErr);
}
// Prompt user, pretend we have data if says 'No'.
const bool hang = !hasData && !finished;
hasData = hang && showTimeOutMessageBox && !askToKill(p.program());
} while (hasData && !finished);
if (syncDebug)
qDebug() << "<readDataFromProcess" << finished;
return finished;
}
// Path utilities
// Locate a binary in a directory, applying all kinds of

View File

@@ -133,16 +133,6 @@ public:
// Create a (derived) processes with flags applied.
static QSharedPointer<QProcess> createProcess(unsigned flags);
// Static helper for running a process synchronously in the foreground with timeout
// detection similar SynchronousProcess' handling (taking effect after no more output
// occurs on stderr/stdout as opposed to waitForFinished()). Returns false if a timeout
// occurs. Checking of the process' exit state/code still has to be done.
static bool readDataFromProcess(QProcess &p,
int timeoutS,
QByteArray *rawStdOut = nullptr,
QByteArray *rawStdErr = nullptr,
bool timeOutMessageBox = false);
// Helpers to find binaries. Do not use it for other path variables
// and file types.
static QString locateBinary(const QString &binary);