Commit bf33ac90 authored by Dario Freddi's avatar Dario Freddi

Start POF of the transaction run

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent e98e65a9
......@@ -13,6 +13,7 @@ akabeilibarchivehelper.cpp
akabeioperation.cpp
akabeioperationrunner.cpp
akabeipackage.cpp
akabeirunnerthread_p.cpp
)
set(AKABEI_OPERATION_SRCS
......
......@@ -100,6 +100,12 @@ Operation::List Operation::subOperations() const
return d->children;
}
QStringList Operation::targetDependencies() const
{
Q_D(const Operation);
return d->deps;
}
void Operation::setCanBeConcurrent(bool concurrent)
{
Q_D(Operation);
......
......@@ -64,6 +64,8 @@ public:
QStringList targetAdditions() const;
QStringList targetRemovals() const;
QStringList targetDependencies() const;
List subOperations() const;
//OperationRunner *runner();
......@@ -100,6 +102,7 @@ private:
OperationPrivate * const d_ptr;
friend class OperationRunner;
friend class RunnerThread;
};
}
......
/* This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "akabeirunnerthread_p.h"
#include <qeventloop.h>
#include <QFile>
#include "akabeiconfig.h"
namespace Akabei
{
RunnerThread::RunnerThread(QObject* parent)
: QThread(parent)
{
}
RunnerThread::~RunnerThread()
{
}
void RunnerThread::requestCancel()
{
}
void RunnerThread::run()
{
// Start from phase 1.
m_currentPhase = Operation::Phase1;
}
void RunnerThread::processNextPhase()
{
// First of all validate everything and compute dependencies. Recurse over one's self
// until all dependencies are satisfied.
QStringList targetNames;
QStringList dependTargets;
foreach (Operation *op, m_operations[m_currentPhase]) {
targetNames << op->targetName();
if (op->status() != Operation::StatusReady) {
// TODO: This might be async as well. Handle this
op->validate();
if (op->status() != Operation::StatusReady) {
//Problems.
// TODO take action
}
dependTargets << op->targetDependencies();
}
}
// Check dependencies
dependTargets.removeDuplicates();
QStringList missingDeps;
foreach (const QString &dep, dependTargets) {
// TODO: Check local database here, and add dependencies
}
if (!missingDeps.isEmpty()) {
// TODO Act upon missing dependencies, add them to the stack
// And recurse
processNextPhase();
return;
}
// Ok, now check validity of stuff. Start by populating some lists
QStringList filesystemAdditions;
QStringList conflictTargets;
foreach (Operation *op, m_operations[m_currentPhase]) {
filesystemAdditions << op->fileSystemAdditions();
conflictTargets << op->conflictingTargets();
}
int dupCount = filesystemAdditions.removeDuplicates();
if (dupCount > 0) {
// Internal conflicts
//TODO handle
}
// Check filesystem itself now
foreach (const QString &target, filesystemAdditions) {
if (QFile::exists(Config::instance()->root() + target)) {
// Problem, FS conflict.
// TODO handle
}
}
// Now check conflicts and act upon them.
foreach (const QString &target, conflictTargets) {
if (targetNames.contains(target)) {
// Problem, attempting to install a package conflicting with itself.
// TODO handle
}
// TODO check the local database
}
// Good. The transaction appears to be fully valid. Now run everything.
// TODO handle concurrency
foreach (Operation *op, m_operations[m_currentPhase]) {
// TODO: This might be async as well. Handle this
op->validate();
if (op->status() != Operation::StatusPerformed) {
//Problems.
// TODO take action
}
}
// Good. Increase the phase and recurse (eventually)
m_currentPhase = (Operation::Phase)((int)m_currentPhase + 1);
if (m_currentPhase > 5) {
// TODO do not recurse here
}
processNextPhase();
}
}
#include "akabeirunnerthread_p.moc"
/* This file is part of the Chakra project
Copyright (C) 2010 Dario Freddi <drf@chakra-project.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#ifndef AKABEI_AKABEIRUNNERTHREAD_P_H
#define AKABEI_AKABEIRUNNERTHREAD_P_H
#include <QtCore/QThread>
#include <QtCore/QHash>
#include "akabeioperation.h"
namespace Akabei {
class RunnerThread : public QThread
{
Q_OBJECT
public:
RunnerThread(QObject* parent = 0);
virtual ~RunnerThread();
void requestCancel();
protected:
virtual void run();
private:
void processNextPhase();
private:
QHash<Operation::Phase, QList< Operation* > > m_operations;
Operation::Phase m_currentPhase;
friend class OperationRunner;
};
}
#endif // AKABEI_AKABEIRUNNERTHREAD_P_H
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