Commit d59506ab authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Lots of fixes for crashes and all and make hooks work again and for all ops

parent 31fc7baf
......@@ -112,8 +112,8 @@ SQLiteResource SQLiteConnection::query(const QString &q)
}
if (retvalue != SQLITE_DONE && retvalue != SQLITE_OK) {
sqlite3_finalize(d->statement);
sqlite3_clear_bindings(d->statement);
sqlite3_finalize(d->statement);
throw SQLiteException(sqlite3_errmsg(d->dbHandle));
}
......
......@@ -321,7 +321,6 @@ Backend::Backend(QObject* parent)
Backend::~Backend()
{
delete d_ptr;
}
void Backend::initialize()
......@@ -716,9 +715,9 @@ Group* Backend::loadGroupFromFile(const QString &path)
while (!in.atEnd()) {
QStringList split( in.readLine().split('=') );
if (split.isEmpty()) {
if (split.isEmpty()) {
continue;
}
}
if (split.first() == "Name") {
group = d->groupPool->group(split.last());
......@@ -733,11 +732,8 @@ Group* Backend::loadGroupFromFile(const QString &path)
Hook* Backend::loadHookFromFile(const QString& path, QList<Package*> pkgs)
{
Hook * hook = 0;
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return hook;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 0;
}
......
......@@ -14,6 +14,7 @@
#include <akabeibackend.h>
#include <akabeioperationrunner.h>
#include <akabeidatabase.h>
#include <akabeidebug.h>
#include <QFileSystemWatcher>
#include <QFutureWatcher>
......@@ -50,6 +51,7 @@ class BackendPrivate : public QObject
: QObject(p)
, q_ptr(p)
, status(Backend::StatusBare)
, localDatabase(0)
, localDatabaseFileHandler(0)
, fsWatcher(new QFileSystemWatcher(p))
, groupPool(new GroupPool)
......@@ -58,9 +60,7 @@ class BackendPrivate : public QObject
delete localDatabaseFileHandler;
qDeleteAll(databases);
delete localDatabase;
delete fsWatcher;
delete groupPool;
delete runner;
}
Backend::Status status;
......
......@@ -267,30 +267,7 @@ Package::List Package::computeDependencies()
//TODO: Version checks!
// TODO: Maybe do something asynchronous?
if (d->dependencies.isEmpty()) { //FIXME: Don't cache it here, but only use it once
/*akabeiDebug() << "Query deps";
QStringList notInstalledDependencies = d->deps;
foreach (const QString &dep, notInstalledDependencies) {
Package::List query = Backend::instance()->localDatabase()->queryPackages("SELECT * FROM packages WHERE Name= \"" + dep + "\" ");
if (!query.isEmpty())
notInstalledDependencies.removeAll(dep);
}
Package::List dependencies;
foreach (const QString &dep, notInstalledDependencies) {
foreach (Database * database, Backend::instance()->databases()) {
Package::List query = database->queryPackages("SELECT * FROM packages WHERE Name= \"" + dep + "\" ");
akabeiDebug() << query;
if (!query.isEmpty()) {
dependencies << query;
break;
}
}
}*/
QStringList deps = d->deps;
QHash<QString, QString> versionedDeps;
foreach (const QString &dep, deps) {
QPair<QString, QString> split = Helpers::versionedTarget(dep);
versionedDeps[split.first] = split.second;
}
QHash<QString, QString> versionedDeps = Helpers::versionedTargets(d->deps);
Package::List dependencies;
for (QHash<QString, QString>::iterator i = versionedDeps.begin(); i != versionedDeps.end(); ++i) {
QString queryString = QString("SELECT * FROM packages WHERE name LIKE \"%1\"")
......@@ -323,7 +300,6 @@ Package::List Package::computeDependencies()
d->dependencies = dependencies;
}
return d->dependencies;
//d->
}
Package::List Package::computeRequiredBy()
......@@ -452,7 +428,7 @@ QList< Hook* > Package::retrieveHooks()
return QList<Hook*>();
if (d->hookCache.isEmpty()) {
QString sql = "SELECT * FROM belongshook JOIN hook ON package=" + QString::number(d->databaseId) + " AND belongshook.hookname=hooks.name;";
QString sql = "SELECT * FROM belongshook JOIN hooks ON package=" + QString::number(d->databaseId) + " AND belongshook.hookname=hooks.name;";
d->hookCache = d->database->queryHooks(sql);
foreach (Hook * hook, d->hookCache)
d->hooks << hook->name();
......@@ -751,9 +727,6 @@ Package* Package::generateInstalledPackage(Package::InstallReason ireason, const
Package *p = new Package(0, -1, name());
p->d_func()->arch = d->arch;
p->d_func()->pathToArchive = d->pathToArchive;
// QStringList backInclMd5;//TODO: Just put in the md5sums in loadPackageFromFile... then we're fine :)
// foreach (const QString &b, d->backup) //Construct some file=md5sum scheme to later know what the original file was
// backInclMd5 << b + '=' + Helpers::md5sumOfFile(Config::instance()->rootDir().absoluteFilePath(b));
p->d_func()->backup = d->backup;
p->d_func()->buildDate = d->buildDate;
p->d_func()->conflicts = d->conflicts;
......
......@@ -303,7 +303,6 @@ void ValidatorRunnable::processNextPhase()
if (!missingDeps.isEmpty()) {
// Do a early recurse
// TODO: Add missing targets here.
processNextPhase();
return;
}
......
......@@ -22,7 +22,7 @@ namespace Akabei {
class PlainHookOperation::Private
{
public:
Private(PlainHookOperation * op) : q(op) {}
Private(PlainHookOperation * op) : q(op), pro(0) {}
~Private() {}
void process();
......@@ -31,8 +31,9 @@ public:
void slotMessage(const QString &mes);
PlainHookOperation *q;
QSet<Hook*> hooks;
QSet<Hook*>::iterator it;
QSet< QPair<Hook*, QString> > hooks;
QSet< QPair<Hook*, QString> >::iterator it;
ChrootedProcess * pro;
};
class HookOpHelper
......@@ -74,16 +75,16 @@ PlainHookOperation::~PlainHookOperation()
delete d;
}
void PlainHookOperation::add(Hook* hook)
void PlainHookOperation::add(Hook* hook, const QString &arg)
{
akabeiDebug() << "Add hook" << hook->name();
d->hooks.insert(hook);
d->hooks.insert(qMakePair<Hook*, QString>(hook, arg));
}
void PlainHookOperation::add(const QList<Hook*> &hooks)
void PlainHookOperation::add(const QList<Hook*> &hooks, const QString &arg)
{
foreach (Hook* hook, hooks)
add(hook);
add(hook, arg);
}
void PlainHookOperation::run()
......@@ -102,12 +103,12 @@ void PlainHookOperation::Private::process()
}
QString root = Config::instance()->root();
ChrootedProcess * process = new ChrootedProcess(q, root);
q->connect(process, SIGNAL(errorsOccured(Akabei::Error::List)), SLOT(slotErrors(Akabei::Error::List)), Qt::DirectConnection);
q->connect(process, SIGNAL(scriptFinished(bool)), SLOT(slotFinished(bool)), Qt::DirectConnection);
q->connect(process, SIGNAL(addMessage(QString)), SLOT(slotMessage(QString)), Qt::DirectConnection);
akabeiDebug() << "Run" << QString("sh %1").arg((*it)->path());
process->run(QString("sh %1").arg((*it)->path()));
pro = new ChrootedProcess(q, root);//The ChrootedProcess deletes itself
q->connect(pro, SIGNAL(errorsOccured(Akabei::Error::List)), SLOT(slotErrors(Akabei::Error::List)), Qt::DirectConnection);
q->connect(pro, SIGNAL(scriptFinished(bool)), SLOT(slotFinished(bool)), Qt::DirectConnection);
q->connect(pro, SIGNAL(addMessage(QString)), SLOT(slotMessage(QString)), Qt::DirectConnection);
akabeiDebug() << "Run" << QString("sh %1 ; %2;").arg(it->first->path()).arg(it->second);
pro->run(QString("sh %1 ; %2;").arg(it->first->path()).arg(it->second));
}
void PlainHookOperation::Private::slotErrors(Akabei::Error::List errors)
......@@ -117,20 +118,23 @@ void PlainHookOperation::Private::slotErrors(Akabei::Error::List errors)
void PlainHookOperation::Private::slotFinished(bool fin)
{
if (fin) {
akabeiDebug() << "Process next";
it++;
process();
if (!fin) {
q->addMessage(tr("There has been an error executing the hook for %1: %2").arg(it->first->name()).arg(pro->errorString()));
}
akabeiDebug() << "Process next" << pro->readAll();
it++;
process();
}
void PlainHookOperation::Private::slotMessage(const QString& mes)
{
akabeiDebug() << "Got a message" << mes;
q->addMessage(mes);
}
void PlainHookOperation::validate()
{
akabeiDebug() << "VALIDATED";
setValidationFinished(true);
}
}
......
......@@ -24,8 +24,8 @@ class AKABEICORESHARED_EXPORT PlainHookOperation : public QObject, public Operat
static PlainHookOperation * instance();
void add(Hook* hook);
void add(const QList<Hook*> &hooks);
void add(Hook* hook, const QString &arg);
void add(const QList<Hook*> &hooks, const QString &arg);
protected:
virtual void run();
......
......@@ -81,7 +81,7 @@ void PlainInstallOperation::run()
/* Sets up the functor to do all the necessary job on the archive entries */
InstallFunctor extractor(backup, this, handle);
handle.handleEntries(extractor);
// Restore the old cwd is we have it.
if (currentDir.exists()) {
chdir(currentDir.absolutePath().toUtf8().data());
......@@ -96,7 +96,7 @@ void PlainInstallOperation::run()
// Generate an install date in UTC format.
QDateTime dt = QDateTime::currentDateTime();
// And set the install reason TODO
Package::InstallReason reason = d->reason;
if (processingOptions().testFlag(InstallAsDependencies)) {
reason = Package::InstalledAsDependencyReason;
......@@ -221,7 +221,7 @@ void PlainInstallOperation::validate()
// Same for hooks.
if (d->package->hasHooks()) {
akabeiDebug() << "We have hooks" << d->package->hooks();
PlainHookOperation::instance()->add(d->package->retrieveHooks());
PlainHookOperation::instance()->add(d->package->retrieveHooks(), "install");
}
}
......
......@@ -103,7 +103,7 @@ void PlainReInstallOperation::run()
try {
/* libarchive requires this for extracting hard links */
chdir(Config::instance()->root().toUtf8().data());
/* Sets up the functor to do all the necessary job on the archive entries */
ReinstallUpgradeFunctor extractor(backup, this, handle);
handle.handleEntries(extractor);
......@@ -122,8 +122,11 @@ void PlainReInstallOperation::run()
/* make an install date (in UTC) */
QDateTime dt = QDateTime::currentDateTime();
// And set the install reason TODO
Package::InstallReason reason = Package::ExplicitlyInstalledReason;
if (processingOptions().testFlag(InstallAsDependencies)) {
reason = Package::InstalledAsDependencyReason;
}
// Create a new package.
Package *p = d->package->generateInstalledPackage(reason, dt);
......@@ -215,7 +218,7 @@ void PlainReInstallOperation::validate()
// Same for hooks
if (d->package->hasHooks()) {
akabeiDebug() << "We have hooks" << d->package->hooks();
PlainHookOperation::instance()->add(d->package->retrieveHooks());
PlainHookOperation::instance()->add(d->package->retrieveHooks(), "install");
}
}
......
......@@ -10,6 +10,7 @@
#include "akabeiplainremoveoperation.h"
#include "akabeiplainscriptletoperation.h"
#include "akabeiplainhookoperation.h"
#include <akabeiconfig.h>
#include <akabeipackage.h>
#include <akabeibackend.h>
......@@ -184,8 +185,9 @@ void PlainRemoveOperation::validate()
}
// Same for hooks
if (!d->package->hasHooks()) {
// TODO add hooks
if (d->package->hasHooks()) {
akabeiDebug() << "We have hooks" << d->package->hooks();
PlainHookOperation::instance()->add(d->package->retrieveHooks(), "remove");
}
}
......
......@@ -56,7 +56,7 @@ void ChrootedProcess::setupChildProcess()
void ChrootedProcess::slotFinished(int exitCode)
{
akabeiDebug() << "Finished" << exitCode;
akabeiDebug() << "Finished" << exitCode << readAllStandardOutput();
// Clean stuff
if (m_file) {
m_file->close();
......@@ -137,7 +137,7 @@ void PlainScriptletOperation::run()
connect(d->process, SIGNAL(errorsOccured(Akabei::Error::List)), SLOT(slotErrors(Akabei::Error::List)), Qt::DirectConnection);
connect(d->process, SIGNAL(scriptFinished(bool)), SLOT(slotFinished(bool)), Qt::DirectConnection);
connect(d->process, SIGNAL(addMessage(QString)), SLOT(slotMessage(QString)), Qt::DirectConnection);
QString toRun = QString("sh %1 %2").arg(d->temp->fileName(), d->args.join(QChar(' ')));
QString toRun = QString("sh %1 ; %2;").arg(d->temp->fileName(), d->args.join(QChar(' ')));
d->process->run(toRun, d->temp);
}
......@@ -156,7 +156,11 @@ void PlainScriptletOperation::slotErrors(Akabei::Error::List errs)
void PlainScriptletOperation::slotFinished(bool fin)
{
akabeiDebug() << "Set finished:" << fin;
setFinished(fin);
akabeiDebug() << d->process->errorString();
if (!fin) {
addMessage(tr("There has been an error executing the scriptlet for %1: %2").arg(d->package->name()).arg(d->process->errorString()));
}
setFinished(true);//We set this true, because we should continue no matter what
}
void PlainScriptletOperation::slotMessage(const QString& mes)
......
......@@ -12,6 +12,7 @@
#include "akabeiplainupgradeoperation.h"
#include "akabeiplainscriptletoperation.h"
#include "akabeioperationutils.h"
#include "akabeiplainhookoperation.h"
#include <akabeipackage.h>
#include <akabeihelpers.h>
......@@ -123,8 +124,13 @@ void PlainUpgradeOperation::run()
/* make an install date (in UTC) */
QDateTime dt = QDateTime::currentDateTime();
// And set the install reason TODO
Package::InstallReason reason = Package::ExplicitlyInstalledReason;
Package::InstallReason reason = d->from->installReason();
if (processingOptions().testFlag(InstallAsDependencies)) {
reason = Package::InstalledAsDependencyReason;
} else if (processingOptions().testFlag(InstallAsExplicit)) {
reason = Package::ExplicitlyInstalledReason;
}
// Create a new package.
Package *p = d->to->generateInstalledPackage(reason, dt);
......@@ -272,7 +278,8 @@ void PlainUpgradeOperation::validate()
// Same for hooks
if (!d->to->hasHooks()) {
// TODO add hooks
akabeiDebug() << "We have hooks" << d->to->hooks();
PlainHookOperation::instance()->add(d->to->retrieveHooks(), "upgrade");
}
}
......
......@@ -214,11 +214,11 @@ void CreateDb::add()
out.flush();
Akabei::Database *db = Akabei::Backend::instance()->loadDatabaseFromFile(unc);
Akabei::Package::List packages;
QString query = "SELECT * FROM packages WHERE";
foreach (const QString &pkgPath, m_targets) {
Akabei::Package * p = Akabei::Backend::instance()->loadPackageFromFile(pkgPath);
if (!p) {
m_targets.removeAll(pkgPath);
continue;
}
......@@ -228,7 +228,8 @@ void CreateDb::add()
packagesCache.insert(pkgPath, p);
}
Akabei::Package::List packages = db->queryPackages(query);
if (!packagesCache.isEmpty())
packages = db->queryPackages(query);
out << "done" << endl;
out.flush();
......@@ -288,7 +289,7 @@ void CreateDb::add()
}
}
out << endl;
out << "Cleaning up..." << endl;
out << "Cleaning up ..." << endl;
out.flush();
if (m_compressed)
......@@ -325,7 +326,7 @@ void CreateDb::remove()
query = query + " OR";
}
Akabei::Package::List packages = db->queryPackages(query);
if (packages.isEmpty()) {
out << "No target requested is present in the database. Quitting..." << endl;
exit(0);
......@@ -362,7 +363,7 @@ void CreateDb::remove()
out.flush();
}
}
out << "done" << endl;
out.flush();
}
......
......@@ -161,7 +161,7 @@ bool DatabaseWorker::add(const QStringList& targets, const QHash< QString, Akabe
foreach (const QString &target, m_targets) {
++idx;
//Is it a group?
if (target.endsWith(".group")) {
Akabei::Backend::instance()->loadGroupFromFile(target);
qDebug() << "Added group:" << target;
......@@ -186,7 +186,7 @@ bool DatabaseWorker::add(const QStringList& targets, const QHash< QString, Akabe
}
continue;
}
Akabei::Package *p = NULL;
// Try loading the package.
......@@ -195,7 +195,7 @@ bool DatabaseWorker::add(const QStringList& targets, const QHash< QString, Akabe
} else {
p = packagesCache[target];
}
if (!p) {
++skipped;
out << target << " appears not to be a valid package, skipping..." << endl;
......@@ -355,7 +355,12 @@ bool DatabaseWorker::add(const QStringList& targets, const QHash< QString, Akabe
QList<Akabei::Hook*> realHooks;
foreach (const QString &h, hookPaths.keys()) {
realHooks << Akabei::Backend::instance()->loadHookFromFile(hookPaths[h], hooks[h]);
Akabei::Hook * hook = Akabei::Backend::instance()->loadHookFromFile(hookPaths[h], hooks[h]);
if (hook) {
realHooks << hook;
} else {
out << "Could not load hook properly:" << h << endl;
}
}
out << ":: Beginning database transaction... ";
......
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