diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-10-19 13:21:06 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-10-19 14:08:44 +0000 |
commit | 095244bc22a11a8a89ed80e6638e0b59ceafdd4e (patch) | |
tree | 72a8a917a3d20433269d7d35a8bfbd958df4d51a | |
parent | 3244432e44c68d8e282820715ae309b90c06c429 (diff) |
lib: Don't ignore the error arg from ostree_* API
Change-Id: Idf0180205cca2a4c2c161289fed5ac94f3e72c3d
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
-rw-r--r-- | src/lib/qotaclientasync.cpp | 63 | ||||
-rw-r--r-- | src/lib/qotaclientasync_p.h | 7 |
2 files changed, 53 insertions, 17 deletions
diff --git a/src/lib/qotaclientasync.cpp b/src/lib/qotaclientasync.cpp index 3688bf0..c1ad64f 100644 --- a/src/lib/qotaclientasync.cpp +++ b/src/lib/qotaclientasync.cpp @@ -146,11 +146,15 @@ QJsonDocument QOTAClientAsync::info(QOTAClientPrivate::QueryTarget target, bool return jsonInfo; } -void QOTAClientAsync::multiprocessLock(const QString &method) +bool QOTAClientAsync::multiprocessLock(const QString &method) { qCDebug(qota) << QTime::currentTime().toString() << method << "- waiting for lock..."; - ostree_sysroot_lock (m_sysroot, 0); + GError *error = Q_NULLPTR; + ostree_sysroot_lock (m_sysroot, &error); + if (emitGError(error)) + return false; qCDebug(qota) << QTime::currentTime().toString() << " lock acquired"; + return true; } void QOTAClientAsync::multiprocessUnlock() @@ -168,8 +172,12 @@ QString QOTAClientAsync::defaultRevision() void QOTAClientAsync::_initialize() { - multiprocessLock(QStringLiteral("_initialize")); - ostree_sysroot_load (m_sysroot, 0, 0); + if (!multiprocessLock(QStringLiteral("_initialize"))) + return; + GError *error = Q_NULLPTR; + ostree_sysroot_load (m_sysroot, 0, &error); + if (emitGError(error)) + return; OstreeDeployment *bootedDeployment = (OstreeDeployment*)ostree_sysroot_get_booted_deployment (m_sysroot); QString bootedRev = QLatin1String(ostree_deployment_get_csum (bootedDeployment)); @@ -187,7 +195,8 @@ void QOTAClientAsync::_initialize() void QOTAClientAsync::_fetchRemoteInfo() { - multiprocessLock(QStringLiteral("_fetchRemoteInfo")); + if (!multiprocessLock(QStringLiteral("_fetchRemoteInfo"))) + return; QString remoteRev; QJsonDocument remoteInfo; bool ok = true; @@ -201,11 +210,12 @@ void QOTAClientAsync::_fetchRemoteInfo() void QOTAClientAsync::_update(const QString &updateToRev) { + if (!multiprocessLock(QStringLiteral("_update"))) + return; bool ok = true; QString defaultRev; QString kernelArgs; - - multiprocessLock(QStringLiteral("_update")); + GError *error = Q_NULLPTR; emit statusStringChanged(QStringLiteral("Checking for missing objects...")); ostree(QString(QStringLiteral("ostree pull qt-os:%1")).arg(updateToRev), &ok, true); multiprocessUnlock(); @@ -216,7 +226,10 @@ void QOTAClientAsync::_update(const QString &updateToRev) if (ok) ostree(QString(QStringLiteral("ostree admin deploy --karg-none %1 linux/qt")).arg(kernelArgs), &ok, true); if (!ok) goto out; - ostree_sysroot_load (m_sysroot, 0, 0); + ostree_sysroot_load (m_sysroot, 0, &error); + if (emitGError(error)) + return; + resetRollbackState(); defaultRev = defaultRevision(); @@ -251,20 +264,37 @@ void QOTAClientAsync::resetRollbackState() emit rollbackChanged(rollbackRev, rollbackInfo, deployments->len); } -void QOTAClientAsync::rollbackFailed(const QString &error) +void QOTAClientAsync::emitRollbackFailed(const QString &error) { emit errorOccurred(error); emit rollbackFinished(QStringLiteral(""), false); multiprocessUnlock(); } +bool QOTAClientAsync::emitGError(GError *error) +{ + if (!error) + return false; + + emit errorOccurred(QString::fromLatin1((error->message))); + multiprocessUnlock(); + return true; +} + void QOTAClientAsync::_rollback() { - multiprocessLock(QStringLiteral("_rollback")); - ostree_sysroot_load (m_sysroot, 0, 0); + if (!multiprocessLock(QStringLiteral("_rollback"))) + return; + GError *error = Q_NULLPTR; + ostree_sysroot_load (m_sysroot, 0, &error); + if (emitGError(error)) + return; + int index = rollbackIndex(); - if (index == -1) - return rollbackFailed(QStringLiteral("At least 2 system versions required for rollback")); + if (index == -1) { + emitRollbackFailed(QStringLiteral("At least 2 system versions required for rollback")); + return; + } g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (m_sysroot); g_autoptr(GPtrArray) newDeployments = g_ptr_array_new_with_free_func (g_object_unref); @@ -276,8 +306,11 @@ void QOTAClientAsync::_rollback() } // atomically update bootloader configuration - if (!ostree_sysroot_write_deployments (m_sysroot, newDeployments, 0, 0)) - return rollbackFailed(QStringLiteral("Failed to update bootloader configuration")); + if (!ostree_sysroot_write_deployments (m_sysroot, newDeployments, 0, &error)) { + emitGError(error); + emitRollbackFailed(QStringLiteral("Failed to update bootloader configuration")); + return; + } resetRollbackState(); QString defaultRev = defaultRevision(); diff --git a/src/lib/qotaclientasync_p.h b/src/lib/qotaclientasync_p.h index 13001d8..09ebd8f 100644 --- a/src/lib/qotaclientasync_p.h +++ b/src/lib/qotaclientasync_p.h @@ -39,6 +39,8 @@ QT_BEGIN_NAMESPACE struct OstreeSysroot; +// from gerror.h +typedef struct _GError GError; class QOTAClientAsync : public QObject { @@ -65,12 +67,13 @@ signals: protected: QString ostree(const QString &command, bool *ok, bool updateStatus = false); QJsonDocument info(QOTAClientPrivate::QueryTarget target, bool *ok, const QString &rev = QString()); - void multiprocessLock(const QString &method); + bool multiprocessLock(const QString &method); void multiprocessUnlock(); QString defaultRevision(); - void rollbackFailed(const QString &error); + void emitRollbackFailed(const QString &error); int rollbackIndex(); void resetRollbackState(); + bool emitGError(GError *error); void _initialize(); void _fetchRemoteInfo(); |