Commit ea0e4996 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Start with the upgrade helper

parent 3c07012f
......@@ -996,7 +996,7 @@ int QueryPerformer::updateFiles(Database *db, Package* from, Package *to)
int QueryPerformer::updateFiles(AbstractSQLiteConnection& db, int from, Package* to)
{
int result = removeFiles(from);
int result = removeFiles(db, from);
if (result != SQLITE_OK)
return result;
result = insertFiles(db, to);
......@@ -1209,12 +1209,17 @@ int QueryPerformer::removeScriptlet(Database *db, Package* p)
return removeScriptlet(d->dbConnection, p);
}
int QueryPerformer::removeScriptlet(AbstractSQLiteConnection &dbConnection, Package* p)
int QueryPerformer::removeScriptlet(AbstractSQLiteConnection& dbConnection, Package* p)
{
return removeScriptlet(dbConnection, p->databaseId());
}
int QueryPerformer::removeScriptlet(AbstractSQLiteConnection &dbConnection, int packageId)
{
QString sqlQuery = "DELETE FROM scriptlets WHERE package = :Package";
try {
dbConnection.bind(":Package", p->databaseId());
dbConnection.bind(":Package", packageId);
dbConnection.query(sqlQuery);
} catch (SQLiteException& e) {
return SQLITE_ABORT;
......
......@@ -124,6 +124,7 @@ namespace QueryPerformer
int AKABEICORESHARED_EXPORT removeScriptlet(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT removeScriptlet(AbstractSQLiteConnection &, Package *p);
int AKABEICORESHARED_EXPORT removeScriptlet(AbstractSQLiteConnection &, int packageId);
int AKABEICORESHARED_EXPORT insertHook(Akabei::Database *db, Hook const* hook);
int AKABEICORESHARED_EXPORT insertHook(AbstractSQLiteConnection &, Hook const* hook);
......
......@@ -44,7 +44,7 @@ QString AKABEICORESHARED_EXPORT selectGroupsNameOrDescription(const QString &, c
* @param comparison the comparison method (LIKE, exact comparison...)
* @param value the property's value.
*/
QString AKABEICORESHARED_EXPORT selectPackages(const QString &, const QString &, const QString &);
QString AKABEICORESHARED_EXPORT selectPackages(const QString &property, const QString &comparison, const QString &value);
/**
* Query to select packages with more freedom.
......
......@@ -135,12 +135,11 @@ void PolkitReInstallOperation::Private::__k__removeFileFinished()
q->setFinished(false);
return;
}
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.archive", QDBusConnection::systemBus());
iface->setProperty("filename", package->pathToArchive());
q->connect(iface, SIGNAL(finished(QString)), SLOT(__k__polkitFinished(QString)));
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/install", "org.chakraproject.akabeicorehelper.installhelper", QDBusConnection::systemBus());
q->connect(iface, SIGNAL(finished(QString, bool)), SLOT(__k__polkitFinished(QString, bool)));
q->connect(iface, SIGNAL(newMessage(QString, QString)), SLOT(__k__newMessage(QString, QString)));
q->connect(iface, SIGNAL(updateProgress(QString, int)), SLOT(__k__progressUpdated(QString, int)));
//FIXME: Use the new installhelper here
iface->asyncCall("upgrade", Akabei::Config::instance()->root(), b, (int) q->processingOptions());
}
......
......@@ -21,6 +21,7 @@
#include <akabeibackend.h>
#include <akabeilog.h>
#include <akabeierror.h>
#include <akabeidatabase.h>
#include <QDateTime>
#include <QStringList>
......@@ -37,9 +38,10 @@ class PolkitUpgradeOperation::Private
delete iface;
}
void __k__polkitFinished(const QString &archive);
void __k__polkitFinished(const QString &archive, bool success);
void __k__progressUpdated(const QString &archive, int progress);
void __k__newMessage(const QString &archive, const QString &message);
void __k__error(const QString &archive, const QString &error);
void __k__removeFileProgress(int progress);
void __k__removeFileFinished();
void __k__removeFileErrors(const QStringList &errors);
......@@ -49,6 +51,7 @@ class PolkitUpgradeOperation::Private
Package *to;
QDBusInterface * iface;
};
PolkitUpgradeOperation::PolkitUpgradeOperation(Package* from, Package* to)
: Operation(to->name())
, d(new Private(from, to, this))
......@@ -100,7 +103,7 @@ void PolkitUpgradeOperation::run()
//NOTE: Do we need error handling here?!
} else {
d->__k__polkitFinished(d->to->pathToArchive());
d->__k__removeFileFinished();
}
}
......@@ -139,28 +142,12 @@ void PolkitUpgradeOperation::Private::__k__removeFileFinished()
q->setFinished(false);
return;
}
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/archive", "org.chakraproject.akabeicorehelper.archive", QDBusConnection::systemBus());
iface->setProperty("filename", to->pathToArchive());
q->connect(iface, SIGNAL(finished(QString)), SLOT(__k__polkitFinished(QString)));
iface = new QDBusInterface("org.chakraproject.akabeicorehelper", "/install", "org.chakraproject.akabeicorehelper.installhelper", QDBusConnection::systemBus());
q->connect(iface, SIGNAL(finished(QString, bool)), SLOT(__k__polkitFinished(QString, bool)));
q->connect(iface, SIGNAL(newMessage(QString, QString)), SLOT(__k__newMessage(QString, QString)));
q->connect(iface, SIGNAL(updateProgress(QString, int)), SLOT(__k__progressUpdated(QString, int)));
iface->asyncCall("upgrade", Akabei::Config::instance()->root(), b, (int) q->processingOptions());
}
void PolkitUpgradeOperation::Private::__k__polkitFinished(const QString &archive)
{
qDebug() << "Finished" << archive;
if (archive != to->pathToArchive())
return;
q->connect(iface, SIGNAL(error(QString,QString)), SLOT(__k__error(QString,QString)));
q->disconnect(iface, SIGNAL(finished(QString)), q, SLOT(__k__polkitFinished(QString)));
q->disconnect(iface, SIGNAL(newMessage(QString, QString)), q, SLOT(__k__newMessage(QString, QString)));
q->disconnect(iface, SIGNAL(updateProgress(QString, int)), q, SLOT(__k__progressUpdated(QString, int)));
/* make an install date (in UTC) */
QDateTime dt = QDateTime::currentDateTime();
Package::InstallReason reason = from->installReason();
if (q->processingOptions().testFlag(InstallAsDependencies)) {
reason = Package::InstalledAsDependencyReason;
......@@ -168,102 +155,33 @@ void PolkitUpgradeOperation::Private::__k__polkitFinished(const QString &archive
reason = Package::ExplicitlyInstalledReason;
}
// Create a new package.
Package *p = to->generateInstalledPackage(reason, dt);
iface->asyncCall("install", to->pathToArchive(), Akabei::Config::instance()->root(), (int) q->processingOptions(), reason, Akabei::Backend::instance()->localDatabase()->name());
}
// Now, db handling. Let's start
int ret = Helpers::QueryPerformer::beginTransaction(Backend::instance()->localDatabase());
if (ret != SQLITE_OK) {
// Problems...
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not begin database transaction!"), q));
q->setFinished(false);
return;
}
qDebug() << "Update package" << QTime::currentTime();
// Insert the entry into the database
// Obtain the query from our helpers
ret = Helpers::QueryPerformer::updatePackage(Backend::instance()->localDatabase(), from, p);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update package in database!"), q));
q->setFinished(false);
return;
}
qDebug() << "Update files" << QTime::currentTime();
// Insert files
ret = Helpers::QueryPerformer::updateFiles(Backend::instance()->localDatabase(), from, p);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update files in database!"), q));
q->setFinished(false);
void PolkitUpgradeOperation::Private::__k__polkitFinished(const QString &archive, bool success)
{
qDebug() << "Finished" << archive;
if (archive != to->pathToArchive())
return;
}
// Scriptlet?
if (p->hasScriptlet() && from->hasScriptlet()) {
// Update
ret = Helpers::QueryPerformer::updateScriptlet(Backend::instance()->localDatabase(), from, p);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update scriptlet in database!"), q));
q->setFinished(false);
return;
}
} else if (p->hasScriptlet()) {
// Insert
ret = Helpers::QueryPerformer::insertScriptlet(Backend::instance()->localDatabase(), p);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not add scriptlet to database!"), q));
q->setFinished(false);
return;
}
} else if (from->hasScriptlet()) {
// Remove
ret = Helpers::QueryPerformer::removeScriptlet(Backend::instance()->localDatabase(), from);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove scriplet from database!"), q));
q->setFinished(false);
return;
}
} /* Otherwise, nothing has to be done: the package has no scriptlet at all */
qDebug() << "commit" << QTime::currentTime();
// Ok, commit the transaction
ret = Helpers::QueryPerformer::commitTransaction(Backend::instance()->localDatabase());
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not commit the transaction!"), q));
q->setFinished(false);
return;
}
qDebug() << "Done, delete it";
q->disconnect(iface, SIGNAL(finished(QString)), q, SLOT(__k__polkitFinished(QString)));
q->disconnect(iface, SIGNAL(newMessage(QString, QString)), q, SLOT(__k__newMessage(QString, QString)));
q->disconnect(iface, SIGNAL(updateProgress(QString, int)), q, SLOT(__k__progressUpdated(QString, int)));
q->disconnect(iface, SIGNAL(error(QString,QString)), q, SLOT(__k__error(QString,QString)));
if (!(q->processingOptions().testFlag(Akabei::DatabaseOnly))) {
// Add the archive to the cache.
// Simply copy it over to our cachedir.
Cache cache;
cache.writePackage(p->pathToArchive(), p->filename());
cache.writePackage(to->pathToArchive(), to->filename());
}
// Delete the package object
delete p;
// Done!
qDebug() << "Before log" << QTime::currentTime();
log() << "upgrade " << to->name() << " (" << from->version().toByteArray() << " -> " << to->version().toByteArray() << ")" << Akabei::endlog;
qDebug() << "After log" << QTime::currentTime();
q->setProgress(100);
q->setFinished(true);
q->setFinished(success);
}
void PolkitUpgradeOperation::Private::__k__progressUpdated(const QString &archive, int progress)
......@@ -278,6 +196,13 @@ void PolkitUpgradeOperation::Private::__k__newMessage(const QString &archive, co
q->addMessage(message);
}
void PolkitUpgradeOperation::Private::__k__error(const QString &archive, const QString &message)
{
if (archive != to->pathToArchive())
return;
q->setErrors(Error::List() << q->errors() << Error(Error::GenericError, message, q));
}
void PolkitUpgradeOperation::validate()
{
// Ok, the archive is valid. Now let's set the conflicting targets & stuff.
......
......@@ -35,9 +35,10 @@ private:
class Private;
Private * const d;
Q_PRIVATE_SLOT(d, void __k__polkitFinished(QString))
Q_PRIVATE_SLOT(d, void __k__polkitFinished(QString, bool))
Q_PRIVATE_SLOT(d, void __k__progressUpdated(QString, int))
Q_PRIVATE_SLOT(d, void __k__newMessage(QString, QString))
Q_PRIVATE_SLOT(d, void __k__error(QString, QString))
Q_PRIVATE_SLOT(d, void __k__removeFileProgress(int))
Q_PRIVATE_SLOT(d, void __k__removeFileFinished())
Q_PRIVATE_SLOT(d, void __k__removeFileErrors(QStringList))
......
......@@ -26,6 +26,7 @@
#include <akabeibackend.h>
#include <akabeihelpers.h>
#include <akabeiconfig.h>
#include <akabeiquery.h>
#include "polkithelper_global.h"
......@@ -189,9 +190,9 @@ void InstallHelper::upgrade(const QString& filename, const QString& root, int pr
QDateTime dt = QDateTime::currentDateTime();
Akabei::Package::InstallReason r = (Akabei::Package::InstallReason)reason;
if (processingOptions().testFlag(InstallAsDependencies)) {
if (options.testFlag(Akabei::InstallAsDependencies)) {
r = Akabei::Package::InstalledAsDependencyReason;
} else if (processingOptions().testFlag(InstallAsExplicit)) {
} else if (options.testFlag(Akabei::InstallAsExplicit)) {
r = Akabei::Package::ExplicitlyInstalledReason;
}
......@@ -207,83 +208,78 @@ void InstallHelper::upgrade(const QString& filename, const QString& root, int pr
return;
}
con.query(Akabei::Queries::selectPackages("name", "LIKE", package->name()));
int fromPackageId = con.getLastRowId();
// Insert the entry into the database
// Obtain the query from our helpers
ret = Akabei::Helpers::QueryPerformer::updatePackage(con, d->from, package);//FIXME get the from packageid from a simple query and use it here
ret = Akabei::Helpers::QueryPerformer::updatePackage(con, fromPackageId, package);
if (ret != SQLITE_OK) {
// Problems...
Akabei::Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update package in database!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not update package in database!"));
setFinished(filename, false);
return;
}
// Insert files
ret = Helpers::QueryPerformer::updateFiles(Backend::instance()->localDatabase(), d->from, p);
ret = Akabei::Helpers::QueryPerformer::updateFiles(con, fromPackageId, package);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update files in database!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not update files in database!"));
setFinished(filename, false);
return;
}
bool hadScriptlet = con.query("SELECT * FROM packages JOIN scriptlets ON packages.id = scriptlets.package WHERE packages.name LIKE \"" + package->name() + "\"").getRowsCount();
// Scriptlet?
if (p->hasScriptlet() && d->from->hasScriptlet()) {
if (package->hasScriptlet() && hadScriptlet) {
// Update
ret = Helpers::QueryPerformer::updateScriptlet(Backend::instance()->localDatabase(), d->from, p);
ret = Akabei::Helpers::QueryPerformer::updateScriptlet(con, fromPackageId, package);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not update scriptlet in database!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not update scriptlet in database!"));
setFinished(filename, false);
return;
}
} else if (p->hasScriptlet()) {
} else if (package->hasScriptlet()) {
// Insert
ret = Helpers::QueryPerformer::insertScriptlet(Backend::instance()->localDatabase(), p);
ret = Akabei::Helpers::QueryPerformer::insertScriptlet(con, package);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not add scriptlet to database!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not add scriptlet to database!"));
setFinished(filename, false);
return;
}
} else if (d->from->hasScriptlet()) {
} else if (hadScriptlet) {
// Remove
ret = Helpers::QueryPerformer::removeScriptlet(Backend::instance()->localDatabase(), d->from);
ret = Akabei::Helpers::QueryPerformer::removeScriptlet(con, fromPackageId);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove scriplet from database!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not remove scriplet from database!"));
setFinished(filename, false);
return;
}
} /* Otherwise, nothing has to be done: the package has no scriptlet at all */
// Ok, commit the transaction
ret = Helpers::QueryPerformer::commitTransaction(Backend::instance()->localDatabase());
ret = Akabei::Helpers::QueryPerformer::commitTransaction(con);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not commit the transaction!"), this));
setFinished(false);
Akabei::Helpers::QueryPerformer::rollbackTransaction(con);
emit error(filename, QObject::tr("Could not commit the transaction!"));
setFinished(filename, false);
return;
}
if (!(processingOptions().testFlag(Akabei::DatabaseOnly))) {
// Add the archive to the cache.
// Simply copy it over to our cachedir.
Cache cache;
cache.writePackage(p->pathToArchive(), p->filename());
}
// Delete the package object
delete package;
delete p;
// Done!
log() << "upgraded " << d->from->name() << "(" << d->from->version().toByteArray() << " -> " << d->to->version().toByteArray() << ")" << Akabei::endlog;
setProgress(100);
setFinished(true);
setFinished(filename, true);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment