forked from microsoft/azurelinux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0002-Make-file-time-available-for-dnf-plugins.patch
More file actions
152 lines (149 loc) · 4.85 KB
/
Copy path0002-Make-file-time-available-for-dnf-plugins.patch
File metadata and controls
152 lines (149 loc) · 4.85 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
diff --git a/ext/repo_rpmmd.c b/ext/repo_rpmmd.c
index 42b7c73..2d3281c 100644
--- a/ext/repo_rpmmd.c
+++ b/ext/repo_rpmmd.c
@@ -842,6 +842,9 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
str = solv_xmlparser_find_attr("build", atts);
if (str && (ti = strtoull(str, 0, 10)) != 0)
repodata_set_num(pd->data, handle, SOLVABLE_BUILDTIME, ti);
+ str = solv_xmlparser_find_attr("file", atts);
+ if (str && (ti = strtoull(str, 0, 10)) != 0)
+ repodata_set_num(pd->data, handle, SOLVABLE_FILETIME, ti);
break;
}
case STATE_SIZE:
diff --git a/src/knownid.h b/src/knownid.h
index 3d558af..abad692 100644
--- a/src/knownid.h
+++ b/src/knownid.h
@@ -274,6 +274,7 @@ KNOWNID(UPDATE_COLLECTIONLIST, "update:collectionlist"), /* list of UPDATE_COLL
KNOWNID(SOLVABLE_MULTIARCH, "solvable:multiarch"), /* debian multi-arch field */
KNOWNID(SOLVABLE_SIGNATUREDATA, "solvable:signaturedata"), /* conda */
KNOWNID(SOLVABLE_ORDERWITHREQUIRES, "solvable:orderwithrequires"), /* rpm */
+KNOWNID(SOLVABLE_FILETIME, "solvable:filetime"), /* file publish time from rpm-md <time file="..."> */
KNOWNID(ID_NUM_INTERNAL, 0)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8a5cd8a..9fda423 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -18,4 +18,12 @@ FOREACH(tcdir testcases libsolv-zypptestcases)
ENDIF ()
ENDFOREACH ()
ENDIF ()
-ENDFOREACH ()
\ No newline at end of file
+ENDFOREACH ()
+
+# Standalone regression test: verify the rpm-md <time file="..."/> attribute
+# is retained as solvable:filetime. repo_add_rpmmd is only built with RPMMD.
+IF (ENABLE_RPMMD)
+ ADD_EXECUTABLE (test_rpmmd_filetime test_rpmmd_filetime.c)
+ TARGET_LINK_LIBRARIES (test_rpmmd_filetime libsolvext libsolv ${SYSTEM_LIBRARIES})
+ ADD_TEST (rpmmd_filetime ${CMAKE_CURRENT_BINARY_DIR}/test_rpmmd_filetime)
+ENDIF (ENABLE_RPMMD)
diff --git a/test/test_rpmmd_filetime.c b/test/test_rpmmd_filetime.c
new file mode 100644
index 0000000..5a9df21
--- /dev/null
+++ b/test/test_rpmmd_filetime.c
@@ -0,0 +1,100 @@
+/*
+ * test_rpmmd_filetime.c
+ *
+ * Regression test for the rpm-md primary.xml parser (ext/repo_rpmmd.c):
+ * the package <time file="..."/> attribute must be recorded as
+ * solvable:filetime. This value is a prerequisite for the DNF
+ * virtual-snapshot plugins.
+ *
+ * If the parsing regresses, filetime is no longer stored and this test
+ * fails, even while the rest of the ctest suite stays green.
+ */
+
+#include <stdio.h>
+
+#include "pool.h"
+#include "repo.h"
+#include "repo_rpmmd.h"
+#include "solv_xfopen.h"
+#include "knownid.h"
+
+/* Minimal rpm-md primary.xml with a single package that carries both a
+ * build time and, crucially, a file publish time (<time file="123">). */
+static const char primary_xml[] =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<metadata xmlns=\"http://linux.duke.edu/metadata/common\""
+" xmlns:rpm=\"http://linux.duke.edu/metadata/rpm\" packages=\"1\">\n"
+" <package type=\"rpm\">\n"
+" <name>filetime-test</name>\n"
+" <arch>x86_64</arch>\n"
+" <version epoch=\"0\" ver=\"1.0\" rel=\"1\"/>\n"
+" <time file=\"123\" build=\"456\"/>\n"
+" </package>\n"
+"</metadata>\n";
+
+int
+main(int argc, char **argv)
+{
+ Pool *pool;
+ Repo *repo;
+ FILE *fp;
+ Id p;
+ Solvable *s;
+ unsigned long long filetime = 0, buildtime = 0;
+ int nsolv = 0;
+
+ (void)argc;
+ (void)argv;
+
+ pool = pool_create();
+ repo = repo_create(pool, "test");
+
+ fp = solv_fmemopen(primary_xml, sizeof(primary_xml) - 1, "r");
+ if (!fp)
+ {
+ fprintf(stderr, "FAIL: solv_fmemopen failed\n");
+ pool_free(pool);
+ return 1;
+ }
+ if (repo_add_rpmmd(repo, fp, 0, 0) != 0)
+ {
+ fprintf(stderr, "FAIL: repo_add_rpmmd: %s\n", pool_errstr(pool));
+ fclose(fp);
+ pool_free(pool);
+ return 1;
+ }
+ fclose(fp);
+
+ FOR_REPO_SOLVABLES(repo, p, s)
+ {
+ nsolv++;
+ buildtime = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
+ filetime = solvable_lookup_num(s, SOLVABLE_FILETIME, 0);
+ }
+
+ if (nsolv != 1)
+ {
+ fprintf(stderr, "FAIL: expected 1 solvable, parsed %d\n", nsolv);
+ pool_free(pool);
+ return 1;
+ }
+ /* Sanity: the pre-existing <time build="..."> handling must still work. */
+ if (buildtime != 456)
+ {
+ fprintf(stderr, "FAIL: solvable:buildtime = %llu, expected 456\n", buildtime);
+ pool_free(pool);
+ return 1;
+ }
+ /* The behavior under test: <time file="123"> must land in filetime. */
+ if (filetime != 123)
+ {
+ fprintf(stderr, "FAIL: solvable:filetime = %llu, expected 123 "
+ "(<time file=\"123\"> not retained)\n", filetime);
+ pool_free(pool);
+ return 1;
+ }
+
+ printf("PASS: <time file=\"123\"> retained as solvable:filetime=%llu\n", filetime);
+ pool_free(pool);
+ return 0;
+}