[PATCH] Support Debian releases without explicit version.
authorMihai Moldovan <ionic@ionic.de>
Tue, 29 Sep 2020 16:30:16 +0000 (18:30 +0200)
committerLuca Boccassi <bluca@debian.org>
Thu, 14 Nov 2024 12:17:18 +0000 (12:17 +0000)
On Debian, some series have no version. Most notably testing, unstable and
experimental.

We have to take this into account, because a missing VERSION_ID tag leads to
test case failures (bad) and DNF context setup failures (much worse).

Fake the version in such a case.

Gbp-Pq: Name 0007-Support-Debian-releases-without-explicit-version.patch

libdnf/dnf-context.cpp

index 1ec782d00fd14eb5d8b2fe78ae42720084bdab2c..32cdc1cc8869733fa90d45c8b9deaf1f76b235d6 100644 (file)
@@ -1726,9 +1726,45 @@ dnf_context_set_os_release(DnfContext *context, GError **error) try
                                                  "os-release",
                                                  "VERSION_ID",
                                                  error);
-    if (maybe_quoted_version == NULL)
-        return FALSE;
-    version = g_shell_unquote(maybe_quoted_version, error);
+    if (maybe_quoted_version == NULL) {
+        /*
+         * On Debian, some series have no version.
+         * Most notably testing, unstable and experimental.
+         *
+         * Fake the version in such a case.
+         * We do not really care a lot about this, since
+         * we're not using DNF in actual Debian contexts,
+         * but make sure that test cases do not fail.
+         */
+        g_autofree gchar *maybe_quoted_id = NULL;
+        maybe_quoted_id = g_key_file_get_string(key_file,
+                                                "os-release",
+                                                "ID",
+                                                error);
+        if (!maybe_quoted_id) {
+            return FALSE;
+        }
+
+        g_autofree gchar *id = g_shell_unquote(maybe_quoted_id, error);
+
+        if (0 != g_ascii_strncasecmp(id, "debian", strlen("debian"))) {
+            /* Better fail non-Debian plattforms... */
+            return FALSE;
+        }
+
+        /*
+         * Distinguishing testing and unstable via the os-release file(s)
+         * is not possible. Using lsb-release would work (as long as it
+         * exists), but requires additional parsing and is overkill.
+         * Just assign a fake version number that is higher than any
+         * existing one.
+         */
+        version = g_strdup("999");
+        g_clear_error(error);
+    }
+    else {
+        version = g_shell_unquote(maybe_quoted_version, error);
+    }
     if (!version)
         return FALSE;
     dnf_context_set_release_ver(context, version);