Commit f3de0c6f authored by Lukas Appelhans's avatar Lukas Appelhans

There we go basic removing done

parent 4ec3e958
......@@ -752,6 +752,13 @@ Hook* Backend::loadHookFromFile(const QString& path, QList<Package*> pkgs)
return hook;
}
Database* Backend::loadDatabaseFromFile(const QString& path)
{
if (!QFile::exists(path))
return 0;
return new Database(path);
}
}
#include "akabeibackend.moc"
......@@ -62,6 +62,7 @@ class AKABEICORESHARED_EXPORT Backend : public QObject
Delta *loadDeltaFromFile(const QString &path);
Group *loadGroupFromFile(const QString &path);
Hook *loadHookFromFile(const QString &path, QList<Package*> pkgs);
Database *loadDatabaseFromFile(const QString &path);
public Q_SLOTS:
void initialize();
......
......@@ -53,6 +53,7 @@ private:
friend class BackendPrivate;
friend class QueryHelper;
friend class Package;
friend class Backend;
};
}
......
......@@ -1334,7 +1334,7 @@ int QueryPerformer::removeDeltas(sqlite3* db, Package *p)
{
// Query first.
QString sqlQuery =
"DELETE FROM hooks WHERE Package = :Package";
"DELETE FROM deltas WHERE Package = :Package";
// Now prepare
sqlite3_stmt *stmt = 0;
......
......@@ -27,10 +27,17 @@
#include <qtemporaryfile.h>
#include <QProcess>
#include <akabeidelta.h>
#include <akabeidatabase.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define ERROR_CHECKPOINT if (ret != SQLITE_OK) { \
out << "Failed! Could not perform the query. SQLite error code: " << ret << ". Skipping target." << endl; \
failed = true; \
break; \
} \
const int MAX_DELTAS = 5;
const int MIN_PACKAGE_SIZE_FOR_DELTA = 3000000;
......@@ -748,8 +755,45 @@ void CreateDb::remove()
}
QHash<QString, QString> files = extractArchive(compressedDbPath);
QString unc = files.value(dbName + ".db");
out << "Created temporary archive:" << unc << endl;
out << "Unpacked database archive to " << unc << endl;
out.flush();
Akabei::Database *db = Akabei::Backend::instance()->loadDatabaseFromFile(unc);
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkg, m_targets) {
query = query + " Name LIKE \"" + pkg + "\"";
if (m_targets.last() != pkg)
query = query + " OR";
}
Akabei::Package::List packages = db->queryPackages(query);
int idx = 0;
bool failed = false;
foreach (Akabei::Package * pkg, packages) { //We don't use a for loop here and have the index, because the index is always 1 behind (due to beginning with 0)
++idx;
out << "Removing " << pkg->name() << " from database (" << idx << "/" << packages.count() << ") ... \r";
out.flush();
int ret = Akabei::Helpers::QueryPerformer::removePackage(db, pkg);
ERROR_CHECKPOINT
ret = Akabei::Helpers::QueryPerformer::removeFiles(db, pkg);
ERROR_CHECKPOINT
if (pkg->hasScriptlet()) {
ret = Akabei::Helpers::QueryPerformer::removeScriptlet(db, pkg);
ERROR_CHECKPOINT
}
if (!pkg->retrieveDeltas().isEmpty()) {
ret = Akabei::Helpers::QueryPerformer::removeDeltas(db, pkg);
ERROR_CHECKPOINT
}
}
out << endl;
if (failed) {
out << "There has been an error during the removal! The temporary database is going to be deleted!" << endl;
delete db;
QFile::remove(unc);
}
}
#include "createdb.moc"
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