Commit a05b6783 authored by Lukas Appelhans's avatar Lukas Appelhans

Split out more ChrootedProcess stuff to be reused later

parent 6a5532d4
......@@ -11,6 +11,7 @@
#include "akabeiplainhookoperation.h"
#include <akabeidatabase.h>
#include <akabeiconfig.h>
#include <QMap>
#include <QSet>
#include <QDebug>
......@@ -47,11 +48,16 @@ AkabeiPlainHookOperation *AkabeiPlainHookOperation::instance()
}
AkabeiPlainHookOperation::AkabeiPlainHookOperation()
: Operation("Hooks"),
: QObject(0),
Operation("Hooks"),
d(new Private())
{
Q_ASSERT(!s_globalHookOp()->q);
s_globalHookOp()->q = this;
setPhase(Phase4);
setPriority(300); // Hooks have a low priority.
setCanBeConcurrent(true); // And it can not be concurrent.
setDescription(tr("Running hooks..."));
}
AkabeiPlainHookOperation::~AkabeiPlainHookOperation()
......@@ -73,6 +79,28 @@ void AkabeiPlainHookOperation::add(Database* db, const QStringList& hooks)
void AkabeiPlainHookOperation::run()
{
qDebug() << "Run hookoperation";
/*QString root = Config::instance()->root();
QDir tempRoot = Config::instance()->rootDir().absoluteFilePath("tmp");
if (!tempRoot.exists()) {
// Create
tempRoot.mkpath(tempRoot.absolutePath());
}
ChrootedProcess * process = new ChrootedProcess(this, root);
connect(process, SIGNAL(errorsOccured(QList<Akabei::Error*>)), SLOT(slotErrors(QList<Akabei::Error*>)));
connect(process, SIGNAL(finished(bool)), SLOT(slotFinished(bool)));
connect(process, SIGNAL(addMessage(QString)), SLOT(slotMessage(QString)));
foreach (Akabei::Database * db, d->hooks) {
foreach (const QString &hook, d->hooks[db]) {
QTemporaryFile temp = new QTemporaryFile(tempRoot.absoluteFilePath("akabei_XXXXXX"));
temp->open();
temp->write(d->package->retrieveScriptlet().toUtf8());
temp->flush();
QString toRun = QString("sh %1").arg(tmpFile->fileName());
process->run(toRun, tmpFile);
}
}*/
setFinished(true);
}
......@@ -80,4 +108,6 @@ void AkabeiPlainHookOperation::validate()
{
setValidationFinished(true);
}
}
\ No newline at end of file
}
#include "akabeiplainhookoperation.moc"
\ No newline at end of file
......@@ -15,7 +15,7 @@
namespace Akabei {
class Database;
class AKABEICORESHARED_EXPORT AkabeiPlainHookOperation : public Operation
class AKABEICORESHARED_EXPORT AkabeiPlainHookOperation : public QObject, public Operation
{
public:
virtual ~AkabeiPlainHookOperation();
......
......@@ -23,10 +23,10 @@
namespace Akabei
{
ChrootedProcess::ChrootedProcess(Operation *op, const QString& chroot, QFile * file, QObject* parent)
ChrootedProcess::ChrootedProcess(Operation *op, const QString& chroot, QObject* parent)
: QProcess(parent)
, m_chroot(chroot)
, m_file(file)
, m_file(0)
, m_operation(op)
{
qDebug() << "Constructed";
......@@ -40,6 +40,12 @@ ChrootedProcess::~ChrootedProcess()
{
}
void ChrootedProcess::run(const QString &cmd, QFile * file)
{
m_file = file;
start(cmd);
}
void ChrootedProcess::setupChildProcess()
{
::chroot(m_chroot.toUtf8().data());
......@@ -50,6 +56,11 @@ void ChrootedProcess::setupChildProcess()
void ChrootedProcess::slotFinished(int exitCode)
{
qDebug() << "Finished" << exitCode;
// Clean stuff
if (m_file) {
m_file->close();
m_file->deleteLater();
}
if (exitCode == 0 || m_operation->processingOptions() & Akabei::Force) {
// Good.
emit finished(true);
......@@ -58,10 +69,6 @@ void ChrootedProcess::slotFinished(int exitCode)
emit errorsOccured(QList<Error*>() << new Akabei::Error(Akabei::Error::ScripletError, tr("Scriptlet failed to executed properly"), m_operation));
emit finished(false);
}
// Clean stuff
m_file->close();
m_file->deleteLater();
deleteLater();
}
......@@ -126,12 +133,12 @@ void PlainScriptletOperation::run()
d->temp->write(d->package->retrieveScriptlet().toUtf8());
d->temp->flush();
d->process = new ChrootedProcess(this, root, d->temp);
d->process = new ChrootedProcess(this, root);
connect(d->process, SIGNAL(errorsOccured(QList<Akabei::Error*>)), SLOT(slotErrors(QList<Akabei::Error*>)));
connect(d->process, SIGNAL(finished(bool)), SLOT(slotFinished(bool)));
connect(d->process, SIGNAL(addMessage(QString)), SLOT(slotMessage(QString)));
QString toRun = QString("sh %1 %2").arg(d->temp->fileName(), d->args.join(QChar(' ')));
d->process->start(toRun);
d->process->run(toRun, d->temp);
}
void PlainScriptletOperation::validate()
......
......@@ -23,8 +23,10 @@ class ChrootedProcess : public QProcess
{
Q_OBJECT
public:
explicit ChrootedProcess(Operation *op, const QString &chroot, QFile * file, QObject* parent = 0);
explicit ChrootedProcess(Operation *op, const QString &chroot, QObject* parent = 0);
virtual ~ChrootedProcess();
void run(const QString &cmd, QFile * file);
protected:
virtual void setupChildProcess();
......
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