Commit 3c07012f authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Start with the upgrade method

parent 8d27d146
......@@ -749,7 +749,12 @@ int QueryPerformer::updatePackage(Database *db, Package* from, Package *to)
return updatePackage(d->dbConnection, from, to);
}
int QueryPerformer::updatePackage(AbstractSQLiteConnection &dbConnection, Package* from, Package* p)
int QueryPerformer::updatePackage(AbstractSQLiteConnection& dbConnection, Package* from, Package* to)
{
return updatePackage(dbConnection, from->databaseId(), to);
}
int QueryPerformer::updatePackage(AbstractSQLiteConnection &dbConnection, int from, Package* p)
{
QString null = "NULL";
......@@ -793,78 +798,78 @@ int QueryPerformer::updatePackage(AbstractSQLiteConnection &dbConnection, Packag
dbConnection.bind(":GitRepo", p->gitRepo());
dbConnection.bind(":GitBranch", p->gitBranch());
dbConnection.bind(":GitFolder", p->gitFolder());
dbConnection.bind(":PreviousPackageId", from->databaseId());
dbConnection.bind(":PreviousPackageId", from);
dbConnection.query(sqlQuery);
QueryHelper::packagePrivateFromPackage(p)->setDatabaseId(from->databaseId());
QueryHelper::packagePrivateFromPackage(p)->setDatabaseId(from);
/*
* Delete every relation
*/
dbConnection.query("DELETE FROM belongsgroup WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM depends WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM optional WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM replaces WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM provides WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM conflicts WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM providesmimetype WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM licensed WHERE package=" + QString::number(from->databaseId()));
dbConnection.query("DELETE FROM belongsgroup WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM depends WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM optional WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM replaces WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM provides WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM conflicts WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM providesmimetype WHERE package=" + QString::number(from));
dbConnection.query("DELETE FROM licensed WHERE package=" + QString::number(from));
foreach (Akabei::Group *group, p->groups()) {
// Can I assume the group already exists?
//dbConnection.query("INSERT INTO groups ('name') VALUES ('" + group->name() + "');");
sqlQuery = "INSERT INTO belongsgroup ('package', 'groupname') VALUES (:Package, :Group);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Group", group->name());
dbConnection.query(sqlQuery);
}
foreach (const QString& dependency, p->dependencies()) {
sqlQuery = "INSERT INTO depends ('package', 'dependency') VALUES (:Package, :Depend);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Depend", dependency);
dbConnection.query(sqlQuery);
}
foreach (const QString& opt, p->optionalDependencies()) {
sqlQuery = "INSERT INTO optional ('package', 'dependency') VALUES (:Package, :OptDepend);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":OptDepend", opt);
dbConnection.query(sqlQuery);
}
foreach (const QString& replace, p->replaces()) {
sqlQuery = "INSERT INTO replaces ('package', 'replaces') VALUES (:Package, :Replace);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Replace", replace);
dbConnection.query(sqlQuery);
}
foreach (const QString& provides, p->provides()) {
sqlQuery = "INSERT INTO provides ('package', 'provides') VALUES (:Package, :Provides);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Provides", provides);
dbConnection.query(sqlQuery);
}
foreach (const QString& conflict, p->conflictsWith()) {
sqlQuery = "INSERT INTO conflicts ('package', 'conflict') VALUES (:Package, :Conflict);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Conflict", conflict);
dbConnection.query(sqlQuery);
}
foreach (const QString &mimetype, p->mimetypes()) {
sqlQuery = "INSERT INTO providesmimetype ('package', 'mimetype') VALUES (:Package, :MimeType);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":MimeType", mimetype);
dbConnection.query(sqlQuery);
}
foreach (const QString& license, p->licenses()) {
sqlQuery = "INSERT INTO licensed ('package', 'license') VALUES (:Package, :License);";
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":License", license);
dbConnection.query(sqlQuery);
}
......@@ -989,6 +994,15 @@ int QueryPerformer::updateFiles(Database *db, Package* from, Package *to)
return updateFiles(d->dbConnection, from, to);
}
int QueryPerformer::updateFiles(AbstractSQLiteConnection& db, int from, Package* to)
{
int result = removeFiles(from);
if (result != SQLITE_OK)
return result;
result = insertFiles(db, to);
return result;
}
int QueryPerformer::updateFiles(AbstractSQLiteConnection &dbConnection, Package* from, Package* to)
{
QString sqlQuery;
......@@ -1074,13 +1088,13 @@ int QueryPerformer::removeFiles(Database *db, Package* p)
return removeFiles(d->dbConnection, p);
}
int QueryPerformer::removeFiles(AbstractSQLiteConnection &dbConnection, Package* p)
{
int QueryPerformer::removeFiles(AbstractSQLiteConnection& dbConnection, int package)
{
// Query first.
QString sqlQuery = "DELETE FROM files WHERE Package=:Package";
try {
dbConnection.bind(":Package", p->databaseId());
dbConnection.bind(":Package", package);
dbConnection.query(sqlQuery);
} catch (SQLiteException& e) {
return SQLITE_ABORT;
......@@ -1089,6 +1103,11 @@ int QueryPerformer::removeFiles(AbstractSQLiteConnection &dbConnection, Package*
return SQLITE_OK;
}
int QueryPerformer::removeFiles(AbstractSQLiteConnection &dbConnection, Package* p)
{
return removeFiles(dbConnection, p->databaseId());
}
int QueryPerformer::insertHook(Database *db, Akabei::Hook const* hook)
{
DatabasePrivate *d = QueryHelper::databasePrivateFromDatabase(db);
......@@ -1164,12 +1183,17 @@ int QueryPerformer::updateScriptlet(Database *db, Package* from, Package *to)
return updateScriptlet(d->dbConnection, from, to);
}
int QueryPerformer::updateScriptlet(AbstractSQLiteConnection &dbConnection, Package* from, Package* to)
int QueryPerformer::updateScriptlet(AbstractSQLiteConnection& db, Package* from, Package* to)
{
return updateScriptlet(db, from->databaseId(), to);
}
int QueryPerformer::updateScriptlet(AbstractSQLiteConnection &dbConnection, int from, Package* to)
{
QString sqlQuery = "UPDATE scriptlets SET scriptlet=:Scriptlet WHERE package=:Package";
try {
dbConnection.bind(":Package", from->databaseId());
dbConnection.bind(":Package", from);
dbConnection.bind(":Scriptlet", to->retrieveScriptlet());
dbConnection.query(sqlQuery);
} catch (SQLiteException& e) {
......
......@@ -85,6 +85,7 @@ namespace QueryPerformer
int AKABEICORESHARED_EXPORT updatePackage(Akabei::Database *db, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updatePackage(AbstractSQLiteConnection &, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updatePackage(AbstractSQLiteConnection &, int from, Package *to);
int AKABEICORESHARED_EXPORT removePackage(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT removePackage(AbstractSQLiteConnection &, Package *p);
......@@ -108,15 +109,18 @@ namespace QueryPerformer
int AKABEICORESHARED_EXPORT updateFiles(Akabei::Database *db, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updateFiles(AbstractSQLiteConnection &, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updateFiles(AbstractSQLiteConnection &, int from, Package *to);
int AKABEICORESHARED_EXPORT removeFiles(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT removeFiles(AbstractSQLiteConnection &, Package *p);
int AKABEICORESHARED_EXPORT removeFiles(AbstractSQLiteConnection &, int package);
int AKABEICORESHARED_EXPORT insertScriptlet(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT insertScriptlet(AbstractSQLiteConnection &, Package *p);
int AKABEICORESHARED_EXPORT updateScriptlet(Akabei::Database *db, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updateScriptlet(AbstractSQLiteConnection &, Package *from, Package *to);
int AKABEICORESHARED_EXPORT updateScriptlet(AbstractSQLiteConnection &, int from, Package *to);
int AKABEICORESHARED_EXPORT removeScriptlet(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT removeScriptlet(AbstractSQLiteConnection &, Package *p);
......
......@@ -156,6 +156,134 @@ void InstallHelper::install(const QString& filename, const QString& root, int pr
void InstallHelper::upgrade(const QString& filename, const QString& root, int processingOptions, int reason, const QString &localdatabase)
{
//FIXME: Implement
qDebug() << "CALLED upgrade";
//FIXME: Change the policy to a new one?
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync("org.chakraproject.akabeicorehelper.archive.extract",
PolkitQt1::SystemBusNameSubject(message().service()),
PolkitQt1::Authority::AllowUserInteraction);
if (auth != PolkitQt1::Authority::Yes || !CHECK_PID) {
return;
}
qDebug() << "UPGRADE" << filename;
Akabei::Package * p = Akabei::Backend::instance()->loadPackageFromFile(filename);
qDebug() << "FOOFOO";
qDebug() << p;
qDebug() << p->filename();
const QMap<QString, QString> backups = p->backupFiles();
Akabei::ProcessingOptions options = (Akabei::ProcessingOptions)processingOptions;
if (!options.testFlag(Akabei::DatabaseOnly)) {
m_archiveHelper->setFilename(filename);
connect(m_archiveHelper, SIGNAL(newMessage(QString,QString)), SIGNAL(newMessage(QString,QString)));
connect(m_archiveHelper, SIGNAL(updateProgress(QString,int)), SIGNAL(updateProgress(QString,int)));
m_archiveHelper->upgrade(root, backups, processingOptions);
}
qDebug() << "DATABASE PART";
m_sqliteHelper->setFilename(localdatabase);
SQLiteConnection & con = m_sqliteHelper->m_connection;
/* make an install date (in UTC) */
QDateTime dt = QDateTime::currentDateTime();
Akabei::Package::InstallReason r = (Akabei::Package::InstallReason)reason;
if (processingOptions().testFlag(InstallAsDependencies)) {
r = Akabei::Package::InstalledAsDependencyReason;
} else if (processingOptions().testFlag(InstallAsExplicit)) {
r = Akabei::Package::ExplicitlyInstalledReason;
}
// Create a new package.
Akabei::Package *package = p->generateInstalledPackage(r, dt);
// Now, db handling. Let's start
int ret = Akabei::Helpers::QueryPerformer::beginTransaction(con);
if (ret != SQLITE_OK) {
// Problems...
emit error(filename, QObject::tr("Could not begin database transaction!"));
setFinished(filename, false);
return;
}
// 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
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);
return;
}
// Insert files
ret = Helpers::QueryPerformer::updateFiles(Backend::instance()->localDatabase(), d->from, p);
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);
return;
}
// Scriptlet?
if (p->hasScriptlet() && d->from->hasScriptlet()) {
// Update
ret = Helpers::QueryPerformer::updateScriptlet(Backend::instance()->localDatabase(), d->from, p);
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);
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());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not add scriptlet to database!"), this));
setFinished(false);
return;
}
} else if (d->from->hasScriptlet()) {
// Remove
ret = Helpers::QueryPerformer::removeScriptlet(Backend::instance()->localDatabase(), d->from);
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);
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());
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);
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 p;
// Done!
log() << "upgraded " << d->from->name() << "(" << d->from->version().toByteArray() << " -> " << d->to->version().toByteArray() << ")" << Akabei::endlog;
setProgress(100);
setFinished(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