Commit 734f4b81 authored by Lukas Appelhans's avatar Lukas Appelhans

Insert hooks into database

parent 5b1f460e
......@@ -407,7 +407,12 @@ QList< Group* > Package::groups() const
return d->groups;
}
QStringList Package::retrieveHooks()
QList< Hook* > Package::retrieveHooks()
{
return QList<Hook*>();//FIXME
}
QStringList Package::hooks()
{
Q_D(Package);
if (d->hooks.isEmpty() && d->hasHooks) {
......@@ -429,13 +434,12 @@ QStringList Package::retrieveHooks()
while (sqlite3_step(statement) == SQLITE_ROW) {
// Add them
d->hooks << QSTRING_FROM_DB(statement, 1);
d->hooks << QSTRING_FROM_DB(statement, 0);
}
sqlite3_finalize(statement);
}
}
return d->hooks;
}
......
......@@ -23,6 +23,7 @@ class Delta;
class Group;
class Database;
class Hook;
class PackagePrivate;
class AKABEICORESHARED_EXPORT Package
......@@ -103,7 +104,8 @@ public:
bool hasHooks() const;
QStringList retrieveFiles();
QStringList retrieveHooks();
QStringList hooks();
QList<Hook*> retrieveHooks();
QString retrieveScriptlet();
List computeDependencies();
......
......@@ -16,6 +16,7 @@
#include <sqlite3.h>
#include <akabeihelpers.h>
#include <akabeicoreconfig.h>
#include <akabeihook.h>
#include <stdlib.h>
#include <QtCore/QDir>
#include <QDebug>
......@@ -288,6 +289,8 @@ void CreateDb::start()
QHash< QString, QList< Akabei::Package* > > packages;
QSet<Akabei::Group*> groups;
QMultiHash< QString, Akabei::Delta* > deltas;
QHash< QString, QString > hookPaths;
QHash< QString, QList< Akabei::Package*> > hooks;
int added = 0;
int addedDeltas = 0;
......@@ -308,6 +311,14 @@ void CreateDb::start()
qDebug() << "Added group:" << target;
continue;
}
//Is it a hook?
if (target.endsWith(".hook")) {
hookPaths[target.split('/').last().remove(".hook")] = target;
qDebug() << "Added hook:" << target;
continue;
}
// Is it a delta?
if (target.endsWith(".delta.tar.xz")) {
// It is. Let's try loading it
......@@ -329,6 +340,9 @@ void CreateDb::start()
out.flush();
continue;
}
foreach (const QString &hook, p->hooks())
hooks[hook] << p;
// Cache it
packages[p->name()] << p;
......@@ -473,6 +487,11 @@ void CreateDb::start()
dbtargets.insert(i.value().first()->name(), i.value().first());
}
}
QList<Akabei::Hook*> realHooks;
foreach (const QString &h, hookPaths.keys()) {
realHooks << Akabei::Backend::instance()->loadHookFromFile(hookPaths[h], hooks[h]);
}
out << ":: Beginning database transaction... ";
out.flush();
......@@ -585,6 +604,29 @@ void CreateDb::start()
}
}
out << endl;
{
out << "Adding hooks to database... (0/" << realHooks.size() << ")\r";
out.flush();
int idx = 0;
// Now let's start adding the various targets
for (QList<Akabei::Hook*>::const_iterator i = realHooks.constBegin(); i != realHooks.constEnd(); ++i) {
++idx;
// Prepare the insert query
int ret = Akabei::Helpers::QueryPerformer::insertHook(db, (*i));
if (ret != SQLITE_OK) {
out << "Failed! Could not perform the query. SQLite error code: " << ret << ". Skipping target." << endl;
//++skipped;
continue;
}
//++added;
out << "Adding hooks to database... (" << idx << '/' << realHooks.size() << ")\r";
out.flush();
}
}
out << endl;
out << ":: * All targets added." << endl;
......
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