Support for ATBUpdateOpkg

This commit is contained in:
Gerhard Hoffmann 2025-02-18 14:56:13 +01:00
parent de9182bdc9
commit b25b66395f
2 changed files with 64 additions and 6 deletions

View File

@ -1,5 +1,8 @@
#include "process/exec_opkg_command.h"
#include "worker.h"
#include "utils_internal.h"
#include <QStringList>
ExecOpkgCommand::ExecOpkgCommand(QString const &command,
Worker *worker,
@ -8,23 +11,75 @@ ExecOpkgCommand::ExecOpkgCommand(QString const &command,
int start_timeout,
int finish_timeout)
: UpdateCommand(command, worker, nextCommandIndex, start_timeout, finish_timeout)
, m_noaction(noaction) {
, m_noaction(noaction)
, m_ok_count{0}
, m_fail_count{0} {
}
void ExecOpkgCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
QProcess *p = (QProcess *)sender();
if (p) {
Worker *w = worker();
if (w) {
if (m_fail_count == 0 && m_ok_count > 0) {
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_SUCCESS, m_noaction);
} else
if (m_ok_count == 0 && m_fail_count > 0) {
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_FAIL, m_noaction);
} else {
// TODO
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_SUCCESS, m_noaction);
}
}
}
return UpdateCommand::finished(exitCode, exitStatus);
}
void ExecOpkgCommand::readyReadStandardOutput() {
QProcess *p = (QProcess *)sender();
if (p) {
QString s = p->readAllStandardOutput();
// TODO
Worker *w = worker();
if (w) {
// static constexpr const char *EXEC_OPKG_COMMANDS_SUCCESS{"success"};
emit w->showExecOpkgStatus(UpdateCommand::EXEC_OPKG_COMMANDS_SUCCESS);
QString s = p->readAllStandardOutput().trimmed();
if (!s.isEmpty()) {
m_standardOutput += s.replace(QChar('\n'), "");
// the command lines in etc/psa_update/opkg_commands are
// separated by "<OPKG>" markers. Note that the file opkg_commands
// itself is *not* changed, of course.
int startIndex, endIndex{};
while (((startIndex = m_standardOutput.indexOf(internal::OPKG_MARKER)) == 0) &&
((endIndex = m_standardOutput.indexOf(internal::OPKG_MARKER, 1)) != -1)) {
QString result = m_standardOutput.mid(0, endIndex).mid(6);
m_standardOutput = m_standardOutput.mid(endIndex);
if (!s.isEmpty()) {
QStringList const lst = result.split(u' ', QString::SkipEmptyParts);
if (lst.size() >= 2) {
if (lst.last() == "ok") {
m_ok_count += 1;
if (lst.contains("noaction")) {
emit w->showExecOpkgCommand(result);
} else {
emit w->showExecOpkgCommand(result);
}
} else {
m_fail_count += 1;
if (lst.contains("noaction")) {
emit w->showExecOpkgCommand(result);
} else {
emit w->showExecOpkgCommand(result);
}
}
} else {
emit w->showExecOpkgCommand(result);
}
}
}
}
}
}
}

View File

@ -6,6 +6,9 @@
class ExecOpkgCommand : public UpdateCommand {
bool m_noaction{false};
QString m_standardOutput{};
int m_ok_count{};
int m_fail_count{};
public:
explicit ExecOpkgCommand(QString const &command,
Worker *worker,