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() ...@@ -92,7 +92,7 @@ void PlainReplaceOperation::run()
foreach (const QString& file, replacedpkg->retrieveFiles()) { foreach (const QString& file, replacedpkg->retrieveFiles()) {
if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) { if ((file.endsWith('/') && !QFileInfo(file).isSymLink()) || (backup.contains(file) && !backup[file].isEmpty())) {
++idx; ++idx;
// It's a directory // It's a directory or a backup file do not remove it
continue; continue;
} }
...@@ -130,19 +130,20 @@ void PlainReplaceOperation::run() ...@@ -130,19 +130,20 @@ void PlainReplaceOperation::run()
} }
} }
// Database handling starts. // Database handling
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;
}
const int numberPackages = d->replaces.count(); const int numberPackages = d->replaces.count();
for (int i = 0; i != numberPackages; ++i) { for (int i = 0; i != numberPackages; ++i) {
Package * replacedpkg = d->replaces[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 // Remove it from DB
// Obtain the query from our helpers // Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg); ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
...@@ -197,6 +198,15 @@ void PlainReplaceOperation::run() ...@@ -197,6 +198,15 @@ void PlainReplaceOperation::run()
// Create a new package. // Create a new package.
Package *p = d->package->generateInstalledPackage(reason, dt); 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. // Insert the entry into the database.
// Obtain the query from our helpers. // Obtain the query from our helpers.
ret = Helpers::QueryPerformer::insertPackage(Backend::instance()->localDatabase(), p); ret = Helpers::QueryPerformer::insertPackage(Backend::instance()->localDatabase(), p);
...@@ -263,10 +273,11 @@ void PlainReplaceOperation::validate() ...@@ -263,10 +273,11 @@ void PlainReplaceOperation::validate()
if (!(processingOptions().testFlag(Akabei::SkipDependencies))) { if (!(processingOptions().testFlag(Akabei::SkipDependencies))) {
// Add additional targets. // Add additional targets.
QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides()); //QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
targets.removeDuplicates(); //targets.removeDuplicates();
setTargetAdditions(targets); //setTargetAdditions(targets);
// Remove the packages that d->package provides since are now replaced
QStringList targetsRemoved; QStringList targetsRemoved;
foreach (Package * r, d->replaces) foreach (Package * r, d->replaces)
targetsRemoved << r->name(); targetsRemoved << r->name();
......
...@@ -149,13 +149,6 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished() ...@@ -149,13 +149,6 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished()
delete iface; delete iface;
// Now, db handling. Let's start // 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; QVariantMap b;
const int numberPackages = replaces.count(); const int numberPackages = replaces.count();
...@@ -167,6 +160,15 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished() ...@@ -167,6 +160,15 @@ void PolkitReplaceOperation::Private::__k__removeFileFinished()
foreach (const QString &k, backup) foreach (const QString &k, backup)
b.insert(k, backup[k]); 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 // Remove it from DB
// Obtain the query from our helpers // Obtain the query from our helpers
ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg); ret = Helpers::QueryPerformer::removePackage(Backend::instance()->localDatabase(), replacedpkg);
...@@ -290,10 +292,11 @@ void PolkitReplaceOperation::validate() ...@@ -290,10 +292,11 @@ void PolkitReplaceOperation::validate()
if (!(processingOptions().testFlag(Akabei::SkipDependencies))) { if (!(processingOptions().testFlag(Akabei::SkipDependencies))) {
// Add additional targets. // Add additional targets.
QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides()); //QStringList targets = QStringList() << d->package->name() << Helpers::unversionedTargets(d->package->provides());
targets.removeDuplicates(); //targets.removeDuplicates();
setTargetAdditions(targets); //setTargetAdditions(targets);
// Remove the packages that d->package provides since are now replaced
QStringList targetsRemoved; QStringList targetsRemoved;
foreach (Package * r, d->replaces) foreach (Package * r, d->replaces)
targetsRemoved << r->name(); 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