Commit 348e8e48 authored by Dario Freddi's avatar Dario Freddi

Add a thread for validation, to separate correctly the two phases

Signed-off-by: default avatarDario Freddi <drf@kde.org>
parent bf33ac90
......@@ -36,91 +36,11 @@ void RunnerThread::run()
{
// Start from phase 1.
m_currentPhase = Operation::Phase1;
processNextPhase();
}
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();
}
}
......
/* 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 "akabeivalidatorthread_p.h"
#include "akabeiconfig.h"
#include <QFile>
using namespace Akabei;
ValidatorThread::ValidatorThread(QObject* parent)
: QThread(parent)
{
}
ValidatorThread::~ValidatorThread()
{
}
void ValidatorThread::requestCancel()
{
}
void ValidatorThread::run()
{
m_currentPhase = Operation::Phase1;
processNextPhase();
}
void ValidatorThread::validateOperation(Operation* op)
{
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
}
}
// Process children
foreach (Operation *child, op->subOperations()) {
validateOperation(child);
}
}
void ValidatorThread::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]) {
validateOperation(op);
}
// 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();
}
/* 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_AKABEIVALIDATORTHREAD_P_H
#define AKABEI_AKABEIVALIDATORTHREAD_P_H
#include "akabeioperation.h"
#include <QtCore/QThread>
#include <QtCore/QHash>
namespace Akabei {
class ValidatorThread : public QThread
{
Q_OBJECT
public:
ValidatorThread(QObject* parent = 0);
virtual ~ValidatorThread();
void requestCancel();
protected:
virtual void run();
private:
void processNextPhase();
void validateOperation(Operation *op);
private:
QHash<Operation::Phase, QList< Operation* > > m_operations;
Operation::Phase m_currentPhase;
friend class OperationRunner;
};
}
#endif // AKABEI_AKABEIVALIDATORTHREAD_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