55 lines
1.9 KiB
C++
Raw Normal View History

2025-02-05 16:25:01 +01:00
#include "update_command.h"
#include "worker.h"
#include <QDebug>
#include <QProcess>
UpdateCommand::UpdateCommand(QString const &command,
Worker *worker,
2025-02-14 13:20:42 +01:00
int nextCommandIndex,
2025-02-05 16:25:01 +01:00
int start_timeout,
int finish_timeout)
2025-02-14 13:20:42 +01:00
: Command(command, start_timeout, finish_timeout)
, m_nextCommandIndex(nextCommandIndex) {
2025-02-05 16:25:01 +01:00
setWorker(worker);
}
bool UpdateCommand::stopUpdateOnFailure() {
return true;
}
void UpdateCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
qCritical() << __func__ << ":" << __LINE__ << m_command
<< "exitCode" << exitCode
<< "exitStatus" << exitStatus;
2025-02-14 13:20:42 +01:00
QProcess *p = qobject_cast<QProcess *>(sender());
2025-02-05 16:25:01 +01:00
if (p) {
// read all remaining data sent to the process, just in case
2025-02-14 13:20:42 +01:00
QString s = p->readAllStandardOutput().trimmed();
if (!s.isEmpty()) {
qCritical() << __func__ << ":" << __LINE__ << s;
m_commandResult += s;
}
qCritical() << __func__ << ":" << __LINE__ << "next command" << m_nextCommandIndex;
2025-02-05 16:25:01 +01:00
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
}
if (!m_worker->workList().empty()) {
if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit) {
2025-02-14 13:20:42 +01:00
qCritical() << __func__ << ":" << __LINE__;
2025-02-05 16:25:01 +01:00
if (m_worker->workList().nextExec()) {
m_worker->workList().exec();
}
} else {
2025-02-14 13:20:42 +01:00
qCritical() << __func__ << ":" << __LINE__;
2025-02-05 16:25:01 +01:00
bool execShowStatus = true;
m_worker->workList().exec(execShowStatus);
}
}
}