Commit 26ae9115 authored by Luca Giambonini's avatar Luca Giambonini

fix, the beginTransaction() was outside the loop, generating a corrupted...

fix, the beginTransaction() was outside the loop, generating a corrupted database with mid transation values

actually we need for each package removed:
for(){
	beginTransaction()
	.... other operations
	commitTransaction()
}

An other solution would be move both begin and commit Transaction out of the loop, but then is no more possible to manage correctly the error in case the transaction is faulty
parent 2f7e6d90
......@@ -92,7 +92,7 @@ void PlainReplaceOperation::run()
foreach (const QString& file, replacedpkg->retrieveFiles()) {
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) {
++idx;
// It's a directory
// It's a directory or a backup file do not remove it
continue;
}
......@@ -130,19 +130,20 @@ void PlainReplaceOperation::run()
}
}
// Database handling starts.
int ret = Helpers::QueryPerformer::beginTransaction(Backend::instance()->localDatabase());
if (ret != SQLITE_OK) {
// Problems...
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not begin database transaction!"), this));
setFinished(false);
return;
}
// Database handling
const int numberPackages = d->replaces.count();
for (int i = 0; i != numberPackages; ++i) {
Package * replacedpkg = d->replaces[i];
// Database handling starts.
int ret = Helpers::QueryPerformer::beginTransaction(Backend::instance()->localDatabase());
if (ret != SQLITE_OK) {
// Problems...
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not begin database transaction!"), this));
setFinished(false);
return;
}
// Remove it from DB
// Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
......@@ -197,6 +198,15 @@ void PlainReplaceOperation::run()
// Create a new package.
Package *p = d->package->generateInstalledPackage(reason, dt);
// Database handling starts.
int ret = Helpers::QueryPerformer::beginTransaction(Backend::instance()->localDatabase());
if (ret != SQLITE_OK) {
// Problems...
setErrors(Error::List() << Error(Error::DatabaseError, QObject::tr("Could not begin database transaction!"), this));
setFinished(false);
return;
}
// Insert the entry into the database.
// Obtain the query from our helpers.
ret = Helpers::QueryPerformer::insertPackage(Backend::instance()->localDatabase(), p);
......@@ -263,10 +273,11 @@ void PlainReplaceOperation::validate()
if (!(processingOptions().testFlag(Akabei::SkipDependencies))) {
// Add additional targets.
QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
targets.removeDuplicates();
setTargetAdditions(targets);
//QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
//targets.removeDuplicates();
//setTargetAdditions(targets);
// Remove the packages that d->package provides since are now replaced
QStringList targetsRemoved;
foreach (Package * r, d->replaces)
targetsRemoved << r->name();
......
......@@ -149,13 +149,6 @@ 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();
......@@ -167,6 +160,15 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished()
foreach (const QString &k, backup)
b.insert(k, backup[k]);
// Start the transacion
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;
}
// Remove it from DB
// Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
......@@ -290,10 +292,11 @@ void PolkitReplaceOperation::validate()
if (!(processingOptions().testFlag(Akabei::SkipDependencies))) {
// Add additional targets.
QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
targets.removeDuplicates();
setTargetAdditions(targets);
//QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
//targets.removeDuplicates();
//setTargetAdditions(targets);
// Remove the packages that d->package provides since are now replaced
QStringList targetsRemoved;
foreach (Package * r, d->replaces)
targetsRemoved << r->name();
......
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