Commit a83161e2 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

rpm-ostree: simplify reading process output

parent e4894de5
......@@ -183,15 +183,12 @@ void RpmOstreeBackend::executeCheckUpdateProcess()
QByteArray readError = process->readAllStandardError();
});
// catch data output
connect(process, &QProcess::readyReadStandardOutput, this, [process, this]() {
QByteArray readOutput = process->readAllStandardOutput();
this->getQProcessUpdateOutput(readOutput);
});
// delete process instance when done, and get the exit status to handle errors.
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) {
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this, process](int exitCode, QProcess::ExitStatus exitStatus) {
qWarning() << "process exited with code " << exitCode << exitStatus;
if (exitCode == 0) {
readUpdateOutput(process);
}
toggleFetching();
process->deleteLater();
});
......@@ -200,13 +197,12 @@ void RpmOstreeBackend::executeCheckUpdateProcess()
process->start(QStringLiteral("rpm-ostree"), {QStringLiteral("update"), QStringLiteral("--check")});
}
void RpmOstreeBackend::getQProcessUpdateOutput(QByteArray readOutput)
void RpmOstreeBackend::readUpdateOutput(QIODevice *device)
{
QList<QByteArray> checkUpdateOutput = readOutput.split('\n');
for (const QByteArray &output : checkUpdateOutput) {
if (output.contains(QByteArray("Version"))) {
m_newVersion = QString::fromLocal8Bit(output);
QTextStream stream(device);
for (QString line = stream.readLine(); stream.readLineInto(&line);) {
if (line.contains(QLatin1String("Version"))) {
m_newVersion = line;
}
}
}
......@@ -224,8 +220,7 @@ void RpmOstreeBackend::executeRemoteRefsProcess()
// catch data output
connect(process, &QProcess::readyReadStandardOutput, this, [process, this]() {
QByteArray readOutput = process->readAllStandardOutput();
this->getQProcessRefsOutput(readOutput);
readRefsOutput(process);
});
// delete process instance when done, and get the exit status to handle errors.
......@@ -240,18 +235,15 @@ void RpmOstreeBackend::executeRemoteRefsProcess()
{QStringLiteral("--repo=/ostree/repo"), QStringLiteral("remote"), QStringLiteral("refs"), QStringLiteral("kinoite")});
}
void RpmOstreeBackend::getQProcessRefsOutput(QByteArray readOutput)
void RpmOstreeBackend::readRefsOutput(QIODevice *device)
{
QList<QByteArray> remoteRefsList;
remoteRefsList = readOutput.split('\n');
QString kinoite = QStringLiteral("kinoite");
const QString kinoite = QStringLiteral("/kinoite");
for (const QByteArray &refs : remoteRefsList) {
QString refsToString = QString::fromLocal8Bit(refs);
if (refsToString.count(kinoite) <= 1)
QTextStream stream(device);
for (QString ref = stream.readLine(); stream.readLineInto(&ref);) {
if (ref.endsWith(kinoite))
continue;
m_remoteRefsList.push_back(refsToString);
m_remoteRefsList.push_back(ref);
}
}
......
......@@ -47,7 +47,7 @@ public:
/*
* Getting the output resulting from executing the QProcess update check.
*/
void getQProcessUpdateOutput(QByteArray readOutput);
void readUpdateOutput(QIODevice *process);
/*
* Calling UpdateDeployment method from the rpm-ostree DBus class when
......@@ -64,7 +64,7 @@ public:
/*
* Getting the output resulting from executing the QProcess remote refs list.
*/
void getQProcessRefsOutput(QByteArray readOutput);
void readRefsOutput(QIODevice *device);
/*
* Setting the current remote refs list to the current running deployment resource.
......@@ -136,4 +136,4 @@ private:
void checkForUpdatesNeeded();
};
#endif
\ No newline at end of file
#endif
......@@ -33,13 +33,12 @@ void RpmOstreeNotifier::recheckSystemUpdateNeeded()
QProcess *process = new QProcess();
connect(process, &QProcess::readyReadStandardError, [process]() {
QByteArray readError = process->readAllStandardError();
qDebug() << "rpm-ostree errors" << process->readAllStandardError().constData();
});
// catch data output
connect(process, &QProcess::readyReadStandardOutput, this, [process, this]() {
QByteArray readOutput = process->readAllStandardOutput();
this->getQProcessOutput(readOutput);
readUpdateOutput(process);
});
// delete process instance when done, and get the exit status to handle errors.
......@@ -60,14 +59,11 @@ void RpmOstreeNotifier::recheckSystemUpdate()
}
}
void RpmOstreeNotifier::getQProcessOutput(QByteArray readOutput)
void RpmOstreeNotifier::readUpdateOutput(QIODevice *device)
{
QList<QByteArray> checkUpdateOutput = readOutput.split('\n');
for (const QByteArray &output : checkUpdateOutput) {
if (output.contains(QByteArray("Version"))) {
m_newUpdate = true;
}
QTextStream stream(device);
for (QString line = stream.readLine(); stream.readLineInto(&line);) {
m_newUpdate |= line.contains(QLatin1String("Version"));
}
}
......
......@@ -42,7 +42,7 @@ private:
* Getting the output resulting from executing the QProcess update check.
* and setting m_newUpdate to true if there is a new version.
*/
void getQProcessOutput(QByteArray readOutput);
void readUpdateOutput(QIODevice *device);
/*
* It is executed whenever there is a change in the tracked file (/tmp/discover-ostree-changed)
......
Supports Markdown
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