Blob Blame History Raw
From 1af71d2964b2e0c28c3c6c0fd6d52bc1adda9507 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= <tim@siosm.fr>
Date: Mon, 18 Mar 2024 14:34:23 +0100
Subject: [PATCH 2/2] rpm-ostree: Fix version checks for container path

Starting with rpm-ostree v2024.3, the version is only set with the
'org.opencontainers.image.version' label and no longer with the
'version' one.

Check the new label first and the old one second to be compatible with
all images.

See:
- https://github.com/coreos/rpm-ostree/releases/tag/v2024.3
- https://github.com/coreos/rpm-ostree/pull/4794
- https://github.com/ostreedev/ostree-rs-ext/pull/581
---
 .../RpmOstreeBackend/RpmOstreeTransaction.cpp     | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libdiscover/backends/RpmOstreeBackend/RpmOstreeTransaction.cpp b/libdiscover/backends/RpmOstreeBackend/RpmOstreeTransaction.cpp
index d3bd5ca47..2b5b1f52e 100644
--- a/libdiscover/backends/RpmOstreeBackend/RpmOstreeTransaction.cpp
+++ b/libdiscover/backends/RpmOstreeBackend/RpmOstreeTransaction.cpp
@@ -215,12 +215,17 @@ void RpmOstreeTransaction::processCommand(int exitCode, QProcess::ExitStatus exi
                 return;
             }
 
-            // Get the version stored in .Labels.version
-            const QString newVersion = jsonDocument.object().value(QLatin1String("Labels")).toObject().value(QLatin1String("version")).toString();
+            // Get the version stored in 'org.opencontainers.image.version' label
+            QString newVersion =
+                jsonDocument.object().value(QLatin1String("Labels")).toObject().value(QLatin1String("org.opencontainers.image.version")).toString();
             if (newVersion.isEmpty()) {
-                qInfo() << "rpm-ostree-backend: Could not get the version from the container labels";
-                setStatus(Status::DoneWithErrorStatus);
-                return;
+                // Check the 'version' label for compatibility with older rpm-ostree releases (< v2024.03)
+                newVersion = jsonDocument.object().value(QLatin1String("Labels")).toObject().value(QLatin1String("version")).toString();
+                if (newVersion.isEmpty()) {
+                    qWarning() << "rpm-ostree-backend: Could not get the version from the container labels";
+                    setStatus(Status::DoneWithErrorStatus);
+                    return;
+                }
             }
 
             QVersionNumber newVersionNumber = QVersionNumber::fromString(newVersion);
-- 
2.44.0