diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-10-21 13:13:19 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-10-25 10:07:35 +0000 |
commit | 833fd98107ae8d1761a41244be61c079a38d1461 (patch) | |
tree | 7884968146fe6e67dbf1b6dc4cbab083dcc90a4b | |
parent | 095244bc22a11a8a89ed80e6638e0b59ceafdd4e (diff) |
Make QOTAClientAsync::ostree thread-safe
Change-Id: I14a195b57e4e997eb881d7eb70a72ef89c328cb6
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
-rw-r--r-- | src/lib/qotaclientasync.cpp | 29 | ||||
-rw-r--r-- | src/lib/qotaclientasync_p.h | 1 |
2 files changed, 11 insertions, 19 deletions
diff --git a/src/lib/qotaclientasync.cpp b/src/lib/qotaclientasync.cpp index c1ad64f..ee7ddc8 100644 --- a/src/lib/qotaclientasync.cpp +++ b/src/lib/qotaclientasync.cpp @@ -38,8 +38,7 @@ QT_BEGIN_NAMESPACE QOTAClientAsync::QOTAClientAsync() : - m_sysroot(ostree_sysroot_new(0)), - m_ostree(0) + m_sysroot(ostree_sysroot_new(0)) { // async mapper connect(this, &QOTAClientAsync::initialize, this, &QOTAClientAsync::_initialize); @@ -50,10 +49,6 @@ QOTAClientAsync::QOTAClientAsync() : QOTAClientAsync::~QOTAClientAsync() { - if (m_ostree) { - m_ostree->waitForFinished(); - delete m_ostree; - } g_object_unref (m_sysroot); } @@ -68,30 +63,28 @@ static void parseErrorString(QString *error) QString QOTAClientAsync::ostree(const QString &command, bool *ok, bool updateStatus) { qCDebug(qota) << command; - if (!m_ostree) { - m_ostree = new QProcess; - m_ostree->setProcessChannelMode(QProcess::MergedChannels); - } - m_ostree->start(command); - if (!m_ostree->waitForStarted()) { + QProcess ostree; + ostree.setProcessChannelMode(QProcess::MergedChannels); + ostree.start(command); + if (!ostree.waitForStarted()) { *ok = false; emit errorOccurred(QLatin1String("Failed to start: ") + command - + QLatin1String(" : ") + m_ostree->errorString()); + + QLatin1String(" : ") + ostree.errorString()); return QString(); } QString out; bool finished = false; do { - finished = m_ostree->waitForFinished(200); - if (!finished && m_ostree->error() != QProcess::Timedout) { + finished = ostree.waitForFinished(200); + if (!finished && ostree.error() != QProcess::Timedout) { *ok = false; emit errorOccurred(QLatin1String("Process failed: ") + command + - QLatin1String(" : ") + m_ostree->errorString()); + QLatin1String(" : ") + ostree.errorString()); return QString(); } - while (m_ostree->canReadLine()) { - QByteArray bytesRead = m_ostree->readLine().trimmed(); + while (ostree.canReadLine()) { + QByteArray bytesRead = ostree.readLine().trimmed(); if (bytesRead.isEmpty()) continue; diff --git a/src/lib/qotaclientasync_p.h b/src/lib/qotaclientasync_p.h index 09ebd8f..d21b085 100644 --- a/src/lib/qotaclientasync_p.h +++ b/src/lib/qotaclientasync_p.h @@ -82,7 +82,6 @@ protected: private: OstreeSysroot *m_sysroot; - QProcess *m_ostree; }; QT_END_NAMESPACE |