Author: dmacvicar
Date: Fri Aug 22 18:10:21 2008
New Revision: 10890
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10890&view=rev
Log:
- add support for arbitrary extendable metadata using external files
- merge diskusage info (modified tag names) supporting in primary or in extension files dskusage definition
- some language preaparation
Modified:
trunk/sat-solver/tools/repo_rpmmd.c
trunk/sat-solver/tools/repo_rpmmd.h
trunk/sat-solver/tools/rpmmd2solv.c
Modified: trunk/sat-solver/tools/repo_rpmmd.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmmd.c?rev=10890&r1=10889&r2=10890&view=diff
==============================================================================
--- trunk/sat-solver/tools/repo_rpmmd.c (original)
+++ trunk/sat-solver/tools/repo_rpmmd.c Fri Aug 22 18:10:21 2008
@@ -22,7 +22,12 @@
enum state {
STATE_START,
+
STATE_METADATA,
+ STATE_OTHERDATA,
+ STATE_DISKUSAGEDATA,
+ STATE_SUSEDATA,
+
STATE_SOLVABLE,
STATE_PRODUCT,
STATE_PATTERN,
@@ -52,6 +57,12 @@
STATE_INSTALLTIME,
STATE_INSTALLONLY,
+ /* Novell/SUSE extended attributes */
+ STATE_EULA,
+ STATE_DISKUSAGE,
+ STATE_DIRS,
+ STATE_DIR,
+
/* patch */
STATE_ID,
STATE_TIMESTAMP,
@@ -117,6 +128,14 @@
};
static struct stateswitch stateswitches[] = {
+ /** fake tag used to enclose 2 different xml files in one **/
+ { STATE_START, "rpmmd", STATE_START, 0 },
+
+ /** tags for different package data, we just ignore the tag **/
+ { STATE_START, "metadata", STATE_START, 0 },
+ { STATE_START, "otherdata", STATE_START, 0 },
+ { STATE_START, "diskusagedata", STATE_START, 0 },
+ { STATE_START, "susedata", STATE_START, 0 },
{ STATE_START, "product", STATE_SOLVABLE, 0 },
{ STATE_START, "pattern", STATE_SOLVABLE, 0 },
@@ -147,6 +166,12 @@
{ STATE_SOLVABLE, "install-only", STATE_INSTALLONLY, 1 },
{ STATE_SOLVABLE, "time", STATE_TIME, 0 },
+ /* extended Novell/SUSE attributes (suseinfo.xml) */
+ { STATE_SOLVABLE, "eula", STATE_EULA, 1 },
+ { STATE_SOLVABLE, "diskusage", STATE_DISKUSAGE, 0 },
+ { STATE_DISKUSAGE, "dirs", STATE_DIRS, 0 },
+ { STATE_DIRS, "dir", STATE_DIR, 0 },
+
// pattern attribute
{ STATE_SOLVABLE, "script", STATE_SCRIPT, 1 },
{ STATE_SOLVABLE, "icon", STATE_ICON, 1 },
@@ -195,6 +220,10 @@
{ NUMSTATES}
};
+/* maxmum initial size of
+ the checksum cache */
+#define MAX_CSCACHE 32768
+#define CSREALLOC_STEP 1024
struct parsedata {
struct parsedata_common common;
@@ -210,7 +239,8 @@
Offset freshens;
struct stateswitch *swtab[NUMSTATES];
enum state sbtab[NUMSTATES];
- const char *lang;
+ /* temporal to store attribute tag language */
+ const char *tmplang;
const char *capkind;
// used to store tmp attributes
// while the tag ends
@@ -221,8 +251,97 @@
Id (*dirs)[3]; // dirid, size, nfiles
int ndirs;
Id langcache[ID_NUM_INTERNAL];
+ /** system language */
+ const char *language;
+
+ /** Hash to maps checksums to solv */
+ Stringpool cspool;
+ /** Cache of known checksums to solvable id */
+ Id *cscache;
+ /* the current longest index in the table */
+ int ncscache;
};
+static Id
+langtag(struct parsedata *pd, Id tag, const char *language)
+{
+ if (language && !language[0])
+ language = 0;
+ if (!language || tag >= ID_NUM_INTERNAL)
+ return pool_id2langid(pd->common.repo->pool, tag, language, 1);
+ return pool_id2langid(pd->common.repo->pool, tag, language, 1);
+ if (!pd->langcache[tag])
+ pd->langcache[tag] = pool_id2langid(pd->common.repo->pool, tag, language, 1);
+ return pd->langcache[tag];
+}
+
+static int
+id3_cmp (const void *v1, const void *v2)
+{
+ Id *i1 = (Id*)v1;
+ Id *i2 = (Id*)v2;
+ return i1[0] - i2[0];
+}
+
+static void
+commit_diskusage (struct parsedata *pd, unsigned handle)
+{
+ unsigned i;
+ Dirpool *dp = &pd->data->dirpool;
+ /* Now sort in dirid order. This ensures that parents come before
+ their children. */
+ if (pd->ndirs > 1)
+ qsort(pd->dirs, pd->ndirs, sizeof (pd->dirs[0]), id3_cmp);
+ /* Substract leaf numbers from all parents to make the numbers
+ non-cumulative. This must be done post-order (i.e. all leafs
+ adjusted before parents). We ensure this by starting at the end of
+ the array moving to the start, hence seeing leafs before parents. */
+ for (i = pd->ndirs; i--;)
+ {
+ unsigned p = dirpool_parent(dp, pd->dirs[i][0]);
+ unsigned j = i;
+ for (; p; p = dirpool_parent(dp, p))
+ {
+ for (; j--;)
+ if (pd->dirs[j][0] == p)
+ break;
+ if (j < pd->ndirs)
+ {
+ if (pd->dirs[j][1] < pd->dirs[i][1])
+ pd->dirs[j][1] = 0;
+ else
+ pd->dirs[j][1] -= pd->dirs[i][1];
+ if (pd->dirs[j][2] < pd->dirs[i][2])
+ pd->dirs[j][2] = 0;
+ else
+ pd->dirs[j][2] -= pd->dirs[i][2];
+ }
+ else
+ /* Haven't found this parent in the list, look further if
+ we maybe find the parents parent. */
+ j = i;
+ }
+ }
+#if 0
+ char sbuf[1024];
+ char *buf = sbuf;
+ unsigned slen = sizeof (sbuf);
+ for (i = 0; i < pd->ndirs; i++)
+ {
+ dir2str (attr, pd->dirs[i][0], &buf, &slen);
+ fprintf (stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
+ }
+ if (buf != sbuf)
+ free (buf);
+#endif
+ for (i = 0; i < pd->ndirs; i++)
+ if (pd->dirs[i][1] || pd->dirs[i][2])
+ {
+ repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
+ }
+ pd->ndirs = 0;
+}
+
/*
* makeevr_atts
@@ -555,15 +674,60 @@
else if (name[2] == 't' && name[3] == 'c')
pd->kind = "patch";
- /* this is a new package */
- /*fprintf(stderr, "new package\n");*/
- pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->common.repo));
- pd->freshens = 0;
- repodata_extend(pd->data, pd->solvable - pool->solvables);
+ /* to support extension metadata files like others.xml which
+ have the following structure:
+
+