Author: matz
Date: Sat Dec 8 05:58:04 2007
New Revision: 8075
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8075&view=rev
Log:
Pfeww. I'm tired, but now you can add refers from repo SOLV files to
attribute store files. Good night.
(Like so:
% addstore bla.solv ding.attr dong.attr > bla2.solv
% dumpsolv bla2.solv
repo refers to 2 attribute stores:
ding.attr has 4 keys
authors
group
keywords
license
dong.attr has 4 keys
authors
keywords
license
...
)
Added:
trunk/sat-solver/tools/addstore.c
Modified:
trunk/sat-solver/src/pool.h
trunk/sat-solver/src/repo.c
trunk/sat-solver/src/repo.h
trunk/sat-solver/src/repo_solv.c
trunk/sat-solver/tools/CMakeLists.txt
trunk/sat-solver/tools/dumpsolv.c
trunk/sat-solver/tools/repo_write.c
Modified: trunk/sat-solver/src/pool.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/pool.h?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/sat-solver/src/pool.h (original)
+++ trunk/sat-solver/src/pool.h Sat Dec 8 05:58:04 2007
@@ -134,7 +134,8 @@
#define TYPE_ATTR_LOCALIDS 10
#define TYPE_COUNT_NAMED 11
-#define TYPE_ATTR_TYPE_MAX 11
+#define TYPE_COUNTED 12
+#define TYPE_ATTR_TYPE_MAX 12
//-----------------------------------------------
Modified: trunk/sat-solver/src/repo.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo.c?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/sat-solver/src/repo.c (original)
+++ trunk/sat-solver/src/repo.c Sat Dec 8 05:58:04 2007
@@ -554,26 +554,43 @@
}
void
-repo_add_attrstore (Repo *repo, Attrstore *s)
+repo_add_attrstore (Repo *repo, Attrstore *s, const char *name)
{
unsigned i;
Repodata *data;
+ /* If this is meant to be the embedded attributes, make sure we don't
+ have them already. */
+ if (!name)
+ {
+ for (i = 0; i < repo->nrepodata; i++)
+ if (repo->repodata[i].name == 0)
+ break;
+ if (i != repo->nrepodata)
+ {
+ pool_debug (repo->pool, SAT_FATAL, "embedded attribs added twice\n");
+ exit (1);
+ }
+ }
repo->nrepodata++;
repo->repodata = xrealloc (repo->repodata, repo->nrepodata * sizeof (*data));
data = repo->repodata + repo->nrepodata - 1;
memset (data, 0, sizeof (*data));
data->s = s;
data->nkeys = s->nkeys;
- if (s->nkeys)
+ /* Don't store the first key, it's {0,0,0}. */
+ data->nkeys--;
+ if (data->nkeys)
{
data->keys = xmalloc (data->nkeys * sizeof (data->keys[0]));
for (i = 0; i < data->nkeys; i++)
{
- data->keys[i].name = s->keys[i].name;
- data->keys[i].type = s->keys[i].type;
+ data->keys[i].name = s->keys[i + 1].name;
+ data->keys[i].type = s->keys[i + 1].type;
}
qsort (data->keys, data->nkeys, sizeof (data->keys[0]), key_cmp);
}
+ if (name)
+ data->name = strdup (name);
}
// EOF
Modified: trunk/sat-solver/src/repo.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo.h?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/sat-solver/src/repo.h (original)
+++ trunk/sat-solver/src/repo.h Sat Dec 8 05:58:04 2007
@@ -32,8 +32,9 @@
/* The attribute store itself. */
Attrstore *s;
/* A filename where to find this attribute store, or where to store
- it. May be NULL, in which case we can't load it on demand or store
- into it. */
+ it. May be "", in which case we can't load it on demand or store
+ into it. It may also be NULL for at most one of the repodata per
+ repo, in which case these are the embedded attributes. */
const char *name;
/* The SHA1 checksum of the file. */
unsigned char checksum[20];
@@ -69,7 +70,7 @@
extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements);
-extern void repo_add_attrstore (Repo *repo, Attrstore *s);
+extern void repo_add_attrstore (Repo *repo, Attrstore *s, const char *name);
static inline const char *repo_name(const Repo *repo)
{
Modified: trunk/sat-solver/src/repo_solv.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo_solv.c?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/sat-solver/src/repo_solv.c (original)
+++ trunk/sat-solver/src/repo_solv.c Sat Dec 8 05:58:04 2007
@@ -183,6 +183,42 @@
}
}
+static void
+read_str (FILE *fp, char **inbuf, unsigned *len)
+{
+ unsigned char *buf = (unsigned char*)*inbuf;
+ if (!buf)
+ {
+ buf = xmalloc (1024);
+ *len = 1024;
+ }
+ int c;
+ unsigned ofs = 0;
+ while((c = getc (fp)) != 0)
+ {
+ if (c == EOF)
+ {
+ pool_debug (mypool, SAT_FATAL, "unexpected EOF\n");
+ exit (1);
+ }
+ /* Plus 1 as we also want to add the 0. */
+ if (ofs + 1 >= *len)
+ {
+ *len += 256;
+ /* Don't realloc on the inbuf, it might be on the stack. */
+ if (buf == (unsigned char*)*inbuf)
+ {
+ buf = xmalloc (*len);
+ memcpy (buf, *inbuf, *len - 256);
+ }
+ else
+ buf = xrealloc (buf, *len);
+ }
+ buf[ofs++] = c;
+ }
+ buf[ofs++] = 0;
+ *inbuf = (char*)buf;
+}
static void
skip_item (FILE *fp, unsigned type, Id *idmap, unsigned numid, unsigned numrel)
@@ -216,6 +252,14 @@
}
}
break;
+ case TYPE_COUNTED:
+ {
+ unsigned count = read_id (fp, 0);
+ unsigned t = read_id (fp, TYPE_ATTR_TYPE_MAX + 1);
+ while (count--)
+ skip_item (fp, t, idmap, numid, numrel);
+ }
+ break;
case TYPE_ATTR_CHUNK:
read_id(fp, 0);
/* Fallthrough. */
@@ -233,6 +277,89 @@
}
}
+static int
+key_cmp (const void *pa, const void *pb)
+{
+ struct key { Id name; unsigned type; };
+ struct key *a = (struct key*)pa;
+ struct key *b = (struct key*)pb;
+ return a->name - b->name;
+}
+
+static void
+parse_repodata (FILE *fp, Id *idmap, unsigned numid, unsigned numrel, Repo *repo)
+{
+ unsigned count = read_id (fp, 0);
+
+ while (count--)
+ {
+ Repodata *data;
+ read_id (fp, numid); /* no name */
+ unsigned type = read_id (fp, TYPE_ATTR_TYPE_MAX + 1);
+ if (type != TYPE_COUNT_NAMED)
+ {
+ skip_item (fp, type, idmap, numid, numrel);
+ continue;
+ }
+ unsigned c = read_id (fp, 0);
+ if (c == 0)
+ continue;
+ if (c != 2)
+ {
+ pool_debug (mypool, SAT_FATAL, "invalid attribute data\n");
+ exit (1);
+ }
+ read_id (fp, numid); /* no name */
+ if (read_id (fp, TYPE_ATTR_TYPE_MAX + 1) != TYPE_STR)
+ {
+ pool_debug (mypool, SAT_FATAL, "invalid attribute data\n");
+ exit (1);
+ }
+ char buf[1024];
+ unsigned len = sizeof (buf);
+ char *filename = buf;
+ read_str (fp, &filename, &len);
+
+ read_id (fp, numid); /* no name */
+ if (read_id (fp, TYPE_ATTR_TYPE_MAX + 1) != TYPE_COUNTED)
+ {
+ pool_debug (mypool, SAT_FATAL, "invalid attribute data\n");
+ exit (1);
+ }
+
+ unsigned nkeys = read_id (fp, 0);
+ if ((nkeys & 1) != 0
+ || read_id (fp, TYPE_ATTR_TYPE_MAX + 1) != TYPE_ID)
+ {
+ pool_debug (mypool, SAT_FATAL, "invalid attribute data\n");
+ exit (1);
+ }
+ nkeys >>= 1;
+
+ repo->nrepodata++;
+ data = xrealloc (repo->repodata, repo->nrepodata * sizeof (*data));
+ repo->repodata = data;
+ data += repo->nrepodata - 1;
+ memset (data, 0, sizeof (*data));
+ data->nkeys = nkeys;
+ if (data->nkeys)
+ {
+ unsigned i;
+ data->keys = xmalloc (data->nkeys * sizeof (data->keys[0]));
+ for (i = 0; i < data->nkeys; i++)
+ {
+ data->keys[i].name = idmap[read_id (fp, numid)];
+ data->keys[i].type = read_id (fp, 0);
+ }
+ qsort (data->keys, data->nkeys, sizeof (data->keys[0]), key_cmp);
+ }
+ data->name = strdup (filename);
+
+ if (filename != buf)
+ xfree (filename);
+ }
+}
+
/*-----------------------------------------------------------------*/
struct key {
@@ -572,7 +699,7 @@
unsigned type = read_id (fp, TYPE_ATTR_TYPE_MAX + 1);
if (type == TYPE_COUNT_NAMED
&& !strcmp (id2str (pool, name), "repodata"))
- skip_item (fp, type, idmap, numid, numrel);
+ parse_repodata (fp, idmap, numid, numrel, repo);
else
skip_item (fp, type, idmap, numid, numrel);
}
@@ -814,7 +941,8 @@
attr_store_pack (embedded_store);
/* If we have any attributes we also have pages. */
read_or_setup_pages (fp, embedded_store);
- repo_add_attrstore (repo, embedded_store);
+ /* The NULL name here means embedded attributes. */
+ repo_add_attrstore (repo, embedded_store, NULL);
}
xfree(idmap);
xfree(schemata);
Modified: trunk/sat-solver/tools/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/CMakeLists.txt?rev=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/sat-solver/tools/CMakeLists.txt (original)
+++ trunk/sat-solver/tools/CMakeLists.txt Sat Dec 8 05:58:04 2007
@@ -47,6 +47,9 @@
ADD_EXECUTABLE( dumpattr ${dumpattr_REPOS} )
TARGET_LINK_LIBRARIES( dumpattr satsolver)
+ADD_EXECUTABLE( addstore addstore.c repo_write.c )
+TARGET_LINK_LIBRARIES( addstore satsolver )
+
install(TARGETS dumpattr
mergesolv
dumpsolv
@@ -55,6 +58,7 @@
helix2solv
rpmmd2solv
rpmdb2solv
+ addstore
DESTINATION ${BIN_INSTALL_DIR} )
install(PROGRAMS repo2solv.sh DESTINATION ${BIN_INSTALL_DIR} )
Added: trunk/sat-solver/tools/addstore.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/addstore.c?rev=8075&view=auto
==============================================================================
--- trunk/sat-solver/tools/addstore.c (added)
+++ trunk/sat-solver/tools/addstore.c Sat Dec 8 05:58:04 2007
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#include