File: 0007-Support-Debian-releases-without-explicit-version.patch

package info (click to toggle)
libdnf 0.69.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,440 kB
  • sloc: cpp: 47,543; xml: 1,638; python: 1,527; ansic: 1,187; sql: 218; sh: 54; makefile: 42
file content (72 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From b1aef4a9d4d5c51fc1d92d12fcc4ddd6fa94d31f Mon Sep 17 00:00:00 2001
From: Mihai Moldovan <ionic@ionic.de>
Date: Tue, 29 Sep 2020 18:30:16 +0200
Subject: [PATCH] Support Debian releases without explicit version.

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.
---
 libdnf/dnf-context.cpp | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/libdnf/dnf-context.cpp b/libdnf/dnf-context.cpp
index 598bff9c..aaa796db 100644
--- a/libdnf/dnf-context.cpp
+++ b/libdnf/dnf-context.cpp
@@ -1666,9 +1666,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);
-- 
2.26.2