RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
Server: rpm5.org Name: Jeff Johnson
Root: /v/rpm/cvs Email: [EMAIL PROTECTED]
Module: rpm Date: 29-Aug-2007 14:50:24
Branch: HEAD Handle: 2007082913502400
Added files:
rpm/tools txar.c
Modified files:
rpm/tools Makefile.am
Log:
preliminaries for converting *.rpm <-> *.xar (of the Leopard-like
persuasion).
Summary:
RevisionChanges Path
2.99+4 -1 rpm/tools/Makefile.am
2.1 +304 -0 rpm/tools/txar.c
patch -p0 <<'@@ .'
Index: rpm/tools/Makefile.am
$ cvs diff -u -r2.98 -r2.99 Makefile.am
--- rpm/tools/Makefile.am 18 Aug 2007 16:45:02 - 2.98
+++ rpm/tools/Makefile.am 29 Aug 2007 12:50:24 - 2.99
@@ -11,7 +11,7 @@
EXTRA_DIST = hashtab.h
-EXTRA_PROGRAMS = debugedit rpmkey
+EXTRA_PROGRAMS = debugedit rpmkey txar
myLDADD = \
$(top_builddir)/build/librpmbuild.la \
@@ -45,6 +45,9 @@
rpmkey_SOURCES =rpmkey.c
rpmkey_LDADD = $(myLDADD) -lkeyutils
+txar_SOURCES = txar.c
+txar_LDADD = $(myLDADD) -lxar
+
##
## provide Berkeley-DB tools
##
@@ .
patch -p0 <<'@@ .'
Index: rpm/tools/txar.c
$ cvs diff -u -r0 -r2.1 txar.c
--- /dev/null 2007-08-29 14:48:57 +0200
+++ txar.c2007-08-29 14:50:24 +0200
@@ -0,0 +1,304 @@
+
+#define RPM2XAR
+#include "system.h"
+#include
+#include
+#include
+#include "debug.h"
+
+static int _debug = 0;
+
+typedef struct rpmmap_s {
+const char * fn;
+FD_t fd;
+void * b;
+size_t nb;
+char * l;
+size_t nl;
+char * s;
+size_t ns;
+char * h;
+size_t nh;
+char * p;
+size_t np;
+xar_t x;
+xar_file_t f;
+xar_iter_t i;
+} * rpmmap;
+
+static rpmmap rpmmapFree(rpmmap map)
+{
+if (map) {
+ int xx;
+
+ if (map->b) {
+ xx = munmap(map->b, map->nb);
+ map->b = NULL;
+ map->nb = 0;
+ } else {
+ map->l = _free(map->l);
+ map->s = _free(map->s);
+ map->h = _free(map->h);
+ map->p = _free(map->p);
+ }
+ if (map->fd) {
+ (void) Fclose(map->fd);
+ map->fd = NULL;
+ }
+ map->fn = _free(map->fn);
+ map = _free(map);
+}
+return NULL;
+}
+
+static rpmmap rpmmapNew(const char * fn)
+{
+rpmmap map = xcalloc(1, sizeof(*map));
+struct stat sb, *st = &sb;
+int xx;
+
+map->fn = xstrdup(fn);
+xx = Stat(map->fn, st);
+map->nb = st->st_size;
+
+return map;
+}
+
+static size_t hSize(uint_32 *p)
+{
+return (8 + 8 + 16 * ntohl(p[2]) + ntohl(p[3]));
+}
+
+static rpmmap rdRPM(const char * rpmfn)
+{
+rpmmap map = rpmmapNew(rpmfn);
+
+map->fd = Fopen(map->fn, "r");
+
+map->b = mmap(NULL, map->nb, PROT_READ, MAP_SHARED, Fileno(map->fd), 0);
+
+map->l = map->b;
+map->nl = 96;
+
+map->s = map->l + map->nl;
+map->ns = hSize((void *)map->s);
+map->ns += (8 - (map->ns % 8)); /* padding */
+
+map->h = map->s + map->ns;
+map->nh = hSize((void *)map->h);
+
+map->p = map->h + map->nh;
+map->np = map->nb;
+map->np -= map->nl + map->ns + map->nh;
+
+return map;
+}
+
+static rpmmap rdXAR(const char * xarfn)
+{
+rpmmap map = rpmmapNew(xarfn);
+
+map->x = xar_open(map->fn, READ);
+
+map->i = xar_iter_new();
+for (map->f = xar_file_first(map->x, map->i);
+ map->f != NULL;
+ map->f = xar_file_next(map->i))
+{
+#if 0
+ const char * key;
+ xar_iter_t p;
+
+ p = xar_iter_new();
+ for (key = xar_prop_first(map->f, p);
+ key != NULL;
+ key = xar_prop_next(p))
+ {
+ const char * val = NULL;
+ xar_prop_get(map->f, key, &val);
+ fprintf(stderr, "key: %s, value: %s\n", key, val);
+ }
+ xar_iter_free(p);
+#else
+ const char * type;
+ const char * name;
+ char * b;
+ size_t nb;
+ int xx;
+
+ b = NULL;
+ nb = 0;
+ xx = xar_extract_tobuffersz(map->x, map->f, &b, &nb);
+if (_debug)
+fprintf(stderr, "*** xx %d %p[%lu]\n", xx, b, (unsigned long)nb);
+ if (xx || b == NULL || nb == 0)
+ continue;
+
+ type = NULL;
+ xx = xar_prop_get(map->f, "type", &type);