Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/bin/patchmanager-daemon/patchmanagerobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,54 @@ bool PatchManagerObject::makePatch(const QDir &root, const QString &patchPath, Q
return true;
}

void PatchManagerObject::updatePatchCompatibility(const QString &projectName, const QStringList compatibility)
{
auto& json = m_metadata[projectName];
if (json[COMPATIBLE_KEY] != compatibility) {
qInfo() << Q_FUNC_INFO << projectName << " updating the compatibility to " << compatibility;
// In memory
json[COMPATIBLE_KEY] = compatibility;
json[ISCOMPATIBLE_KEY] = compatibility.contains(m_osRelease);

// Read patch.json
auto patchPath = json[PATCH_KEY].toString();
auto patchDir = QDir(PATCHES_DIR);
if (!patchDir.cd(patchPath)) {
qWarning() << Q_FUNC_INFO << "Cannot cd to " << patchDir.path();
return;
}

QFile file(patchDir.absoluteFilePath(PATCH_FILE));
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << Q_FUNC_INFO << "Cannot find " << file.fileName() << " in " << patchDir.path();
return;
}


QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(file.readAll(), &error);
QJsonObject jsonObject = document.object();
file.close();

// Write patch.json
jsonObject[COMPATIBLE_KEY] = QJsonArray::fromStringList(compatibility);

if (error.error != QJsonParseError::NoError) {
qWarning() << Q_FUNC_INFO << error.errorString();
return;
}

if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qWarning() << Q_FUNC_INFO << "Cannot write " << file.fileName() << " in " << patchDir.path();
return;
}

file.write(QJsonDocument(jsonObject).toJson());

}
}


void PatchManagerObject::notify(const QString &patch, NotifyAction action)
{
qDebug() << Q_FUNC_INFO << patch << action;
Expand Down Expand Up @@ -2400,19 +2448,24 @@ void PatchManagerObject::requestCheckForUpdates()

QString latestVersion = patchVersion;

QStringList compatibleNow{}; // Used to detect changes in 'compatible' field.
const QVariantList files = project.value("files").toList();
for (const QVariant &fileVar : files) {
const QVariantMap file = fileVar.toMap();
const QStringList compatible = file.value("compatible").toStringList();
if (!compatible.contains(m_osRelease)) {
continue;
}
compatibleNow = compatible;
const QString version = file.value("version").toString();
latestVersion = PatchManagerObject::maxVersion(latestVersion, version);
}

if (latestVersion == patchVersion) {
qDebug() << Q_FUNC_INFO << projectName << "versions match";
if (compatibleNow.length()) {
updatePatchCompatibility(projectName, compatibleNow);
}
return;
}
qDebug() << Q_FUNC_INFO << "available:" << projectName << "version:" << latestVersion;
Expand Down
1 change: 1 addition & 0 deletions src/bin/patchmanager-daemon/patchmanagerobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private slots:

QList<QVariantMap> listPatchesFromDir(const QString &dir, QSet<QString> &existingPatches, bool existing = true);
bool makePatch(const QDir &root, const QString &patchPath, QVariantMap &patch, bool available);
void updatePatchCompatibility(const QString &projectName, const QStringList compatibility);
void notify(const QString &patch, PatchManagerObject::NotifyAction action);

QSet<QString> getAppliedPatches() const;
Expand Down