From e10b5a4dbbfd8705edfadf3c3b113d02460ccb33 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 4 May 2021 07:49:33 +0200 Subject: [PATCH] Utils: Remove SynchronousProcess::readDataFromProcess helper QtcProcess can do that nowadays. Change-Id: Ic3b08146263da2eb189f043eb743c621c18b82c8 Reviewed-by: Christian Stenger --- src/libs/utils/qtcprocess.cpp | 5 +++ src/libs/utils/synchronousprocess.cpp | 44 --------------------------- src/libs/utils/synchronousprocess.h | 10 ------ 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index e67ed326624..b9507d8d91c 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -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, diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index a52fbd8f7ec..cb2e1a5832e 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -645,50 +645,6 @@ QSharedPointer SynchronousProcess::createProcess(unsigned flags) return QSharedPointer(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() << " 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);