Skip to content

Commit

Permalink
[developermode] Refresh package cache before resolving developer mode…
Browse files Browse the repository at this point in the history
… packages. Contributes to JB#41708
  • Loading branch information
rainemak committed Apr 25, 2018
1 parent 1dc122a commit 6e6e3b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions rpm/nemo-qml-plugin-systemsettings.spec
Expand Up @@ -27,6 +27,7 @@ BuildRequires: pkgconfig(nemomodels-qt5)
BuildRequires: pkgconfig(libsailfishkeyprovider) >= 0.0.14
BuildRequires: pkgconfig(connman-qt5) >= 1.2.7
BuildRequires: pkgconfig(ssu-sysinfo) >= 1.1.0
BuildRequires: pkgconfig(packagekitqt5)

%description
%{summary}.
Expand Down
33 changes: 22 additions & 11 deletions src/developermodesettings.cpp
Expand Up @@ -31,8 +31,8 @@
*/

#include "developermodesettings.h"
#include "logging_p.h"

#include <QDebug>
#include <QFile>
#include <QDir>
#include <QDBusReply>
Expand All @@ -41,6 +41,8 @@
#include <getdef.h>
#include <pwd.h>

#include <daemon.h>

/* Symbolic constants */
#define PROGRESS_INDETERMINATE (-1)

Expand Down Expand Up @@ -173,12 +175,22 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
if ((pwd = getpwuid(uid)) != NULL) {
m_username = QString(pwd->pw_name);
} else {
qWarning() << "Failed to return username using getpwuid()";
qCWarning(lcDeveloperModeLog) << "Failed to return username using getpwuid()";
}


if (!m_developerModeEnabled) {
m_workerStatus = CheckingStatus;
executePackageKitCommand(&DeveloperModeSettings::resolvePackageId, DEVELOPER_MODE_PACKAGE);
PackageKit::Transaction *transaction = PackageKit::Daemon::refreshCache(true);

connect(transaction, &PackageKit::Transaction::errorCode, this, [this](PackageKit::Transaction::Error error, const QString &details) {
qCWarning(lcDeveloperModeLog) << "Failed to refresh package cache:" << error << details;
});

connect(transaction, &PackageKit::Transaction::finished, this, [this](PackageKit::Transaction::Exit status, uint runtime) {
qCDebug(lcDeveloperModeLog) << "Package kit cache updated:" << status << runtime;
executePackageKitCommand(&DeveloperModeSettings::resolvePackageId, DEVELOPER_MODE_PACKAGE);
});
}

refresh();
Expand Down Expand Up @@ -322,8 +334,8 @@ DeveloperModeSettings::refresh()

foreach (const QString &device, entries.keys()) {
QString ip = entries[device];
qDebug() << "Device:" << device
<< "IP:" << ip;
qCDebug(lcDeveloperModeLog) << "Device:" << device
<< "IP:" << ip;
}
}

Expand Down Expand Up @@ -356,6 +368,7 @@ static QDBusPendingCallWatcher *packageKitTransactionCall(

QDBusPendingCallWatcher *DeveloperModeSettings::resolvePackageId(const QString &packageName)
{

connectTransactionSignal(
PACKAGEKIT_TRANSACTION_PACKAGE,
SLOT(transactionPackage(uint,QString)));
Expand Down Expand Up @@ -438,6 +451,7 @@ void DeveloperModeSettings::executePackageKitCommand(
m_pendingPackageKitCall = nullptr;

QDBusReply<QDBusObjectPath> reply = *watcher;

if (reply.isValid()) {
m_packageKitTransaction = reply.value();

Expand All @@ -457,14 +471,14 @@ void DeveloperModeSettings::executePackageKitCommand(

QDBusReply<void> reply = *watcher;
if (!reply.isValid()) {
qWarning() << "Failed to call PackageKit method" << reply.error().message();
qCWarning(lcDeveloperModeLog) << "Failed to call PackageKit method" << reply.error().message();

m_workerStatus = Idle;
emit workerStatusChanged();
}
});
} else {
qWarning() << "Failed to create PackageKit transaction" << reply.error().message();
qCWarning(lcDeveloperModeLog) << "Failed to create PackageKit transaction" << reply.error().message();

m_workerStatus = Idle;
emit workerStatusChanged();
Expand Down Expand Up @@ -493,7 +507,6 @@ void DeveloperModeSettings::transactionPackage(uint, const QString &packageId)
void DeveloperModeSettings::transactionPropertiesChanged(
const QString &interface, const QVariantMap &changed, const QStringList &)
{
qDebug() << "properties changed" << interface << changed;

// Expected changes from PackageKit when installing packages:
// 1. Change to 'resolve' role
Expand Down Expand Up @@ -611,8 +624,7 @@ void DeveloperModeSettings::transactionPropertiesChanged(

void DeveloperModeSettings::transactionErrorCode(uint code, const QString &message)
{
qWarning() << "PackageKit error" << code << message;

qCWarning(lcDeveloperModeLog) << "Transaction error:" << code << message;
QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(
PACKAGEKIT_SERVICE,
m_packageKitTransaction.path(),
Expand All @@ -626,7 +638,6 @@ void DeveloperModeSettings::transactionFinished(uint, uint)

const bool enabled = m_developerModeEnabled;
m_developerModeEnabled = QFile::exists(DEVELOPER_MODE_PROVIDED_FILE);

m_workerStatus = Idle;
m_workerProgress = PROGRESS_INDETERMINATE;

Expand Down
1 change: 1 addition & 0 deletions src/logging.cpp
Expand Up @@ -32,3 +32,4 @@
#include "logging_p.h"

Q_LOGGING_CATEGORY(lcVpnLog, "org.sailfishos.settings.vpn", QtWarningMsg)
Q_LOGGING_CATEGORY(lcDeveloperModeLog, "org.sailfishos.settings.developermode", QtWarningMsg)
1 change: 1 addition & 0 deletions src/logging_p.h
Expand Up @@ -35,5 +35,6 @@
#include <QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(lcVpnLog)
Q_DECLARE_LOGGING_CATEGORY(lcDeveloperModeLog)

#endif
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -7,7 +7,7 @@ QT -= gui

CONFIG += c++11 hide_symbols link_pkgconfig
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5
PKGCONFIG += ssu-sysinfo nemodbus
PKGCONFIG += ssu-sysinfo nemodbus packagekitqt5

system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
system(qdbusxml2cpp -c ConnmanVpnProxy -p connmanvpnproxy ../dbus/net.connman.vpn.xml -i qdbusxml2cpp_dbus_types.h)
Expand Down

0 comments on commit 6e6e3b2

Please sign in to comment.