Commit 5ffa0545 authored by Luca Giambonini's avatar Luca Giambonini

update the local database by removing replaced pkgs after the replace operation is finished.

parent 02e05aa2
......@@ -199,8 +199,60 @@ void PlainReplaceOperation::run()
// Delete Package object.
delete p;
const int numberPackages = d->replaces.count();
for (int i = 0; i != numberPackages; ++i) {
Package * replacedpkg = d->replaces[i];
// Remove it from DB
// Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove package from database!"), this));
setFinished(false);
return;
}
// Remove files
ret = Helpers::QueryPerformer::removeFiles(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove files from database!"), this));
setFinished(false);
return;
}
// Scriptlet?
if (replacedpkg->hasScriptlet()) {
ret = Helpers::QueryPerformer::removeScriptlet(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove scriptlet!"), this));
setFinished(false);
return;
}
}
// 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;
}
// Done!
log() << "removed " << replacedpkg->name() << " (" << replacedpkg->version().toByteArray() << ")" << Akabei::endlog;
}
// Done!
log() << "replaced " << d->package->name() << " (" << d->package->version().toByteArray() << ")" << Akabei::endlog;
log() << "replaced with " << d->package->name() << " (" << d->package->version().toByteArray() << ")" << Akabei::endlog;
setProgress(100);
setFinished(true);
}
......
......@@ -147,13 +147,70 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished()
delete iface;
// 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;
}
QVariantMap b;
const int numberPackages = replaces.count();
for (int i = 0; i != numberPackages; ++i) {
Package * replacedpkg = replaces[i];
// get the list of backup files for the replaced packages
QMap<QString, QString> backup = replacedpkg->backupFiles();
foreach (const QString &k, backup)
b.insert(k, backup[k]);
// Remove it from DB
// Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove package from database!"), q));
q->setFinished(false);
return;
}
// Remove files
ret = Helpers::QueryPerformer::removeFiles(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove files from database!"), q));
q->setFinished(false);
return;
}
// Scriptlet?
if (replacedpkg->hasScriptlet()) {
ret = Helpers::QueryPerformer::removeScriptlet(Backend::instance()->localDatabase(), replacedpkg);
if (ret != SQLITE_OK) {
// Problems...
Helpers::QueryPerformer::rollbackTransaction(Backend::instance()->localDatabase());
q->setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not remove scriptlet!"), q));
q->setFinished(false);
return;
}
}
// 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;
}
// Done!
log() << "removed " << replacedpkg->name() << " (" << replacedpkg->version().toByteArray() << ")" << Akabei::endlog;
}
......
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