Skip to content

Commit 3f6bee6

Browse files
committed
Parse boolean values in comps xml
Before this change, the resulting value was true if the attribute was present, false otherwise. After this change, the resulting value is true if the attribute value is "true", false if "false" and default value otherwise. This is the same how libcomps parses the comps xml.
1 parent 148169b commit 3f6bee6

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

ext/repo_comps.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818
#include <assert.h>
19+
#include <stdbool.h>
1920

2021
#include "pool.h"
2122
#include "repo.h"
@@ -100,6 +101,21 @@ struct parsedata {
100101
};
101102

102103

104+
const bool COMPS_DEFAULT_USERVISIBLE = true;
105+
const bool COMPS_DEFAULT_DEFAULT = false;
106+
107+
108+
/* Return true if "true", false if "false", default_value otherwise */
109+
bool
110+
parse_boolean(char *content, bool default_value)
111+
{
112+
if (!strcmp(content, "true"))
113+
return true;
114+
if (!strcmp(content, "false"))
115+
return false;
116+
return default_value;
117+
}
118+
103119

104120
static void
105121
startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
@@ -115,6 +131,10 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
115131
s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
116132
pd->handle = s - pool->solvables;
117133
pd->kind = state == STATE_GROUP ? "group" : "category";
134+
if (COMPS_DEFAULT_USERVISIBLE)
135+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
136+
if (COMPS_DEFAULT_DEFAULT)
137+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
118138
break;
119139

120140
case STATE_NAME:
@@ -193,11 +213,17 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
193213
break;
194214

195215
case STATE_USERVISIBLE:
196-
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
216+
if (parse_boolean(content, COMPS_DEFAULT_USERVISIBLE))
217+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
218+
else
219+
repodata_unset(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
197220
break;
198221

199222
case STATE_DEFAULT:
200-
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
223+
if (parse_boolean(content, COMPS_DEFAULT_DEFAULT))
224+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
225+
else
226+
repodata_unset(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
201227
break;
202228

203229
case STATE_LANG_ONLY:

0 commit comments

Comments
 (0)