RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/tools/ txar.c

From: Jeff Johnson <jbj@rpm5.org>
Date: Wed 29 Aug 2007 - 22:39:55 CEST
Message-Id: <20070829203955.D333A34845B@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   29-Aug-2007 22:39:55
  Branch: HEAD                             Handle: 2007082921395500

  Modified files:
    rpm/tools               txar.c

  Log:
    work-in-progress.

  Summary:
    Revision    Changes     Path
    2.2         +227 -23    rpm/tools/txar.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/tools/txar.c
  ============================================================================
  $ cvs diff -u -r2.1 -r2.2 txar.c
  --- rpm/tools/txar.c	29 Aug 2007 12:50:24 -0000	2.1
  +++ rpm/tools/txar.c	29 Aug 2007 20:39:55 -0000	2.2
  @@ -1,12 +1,15 @@
   
   #define	RPM2XAR
   #include "system.h"
  +#include <inttypes.h>
   #include <xar/xar.h>
   #include <rpmio.h>
   #include <rpmcli.h>
   #include "debug.h"
   
   static int _debug = 0;
  +static int _display = 0;
  +static int _explode = 0;
   
   typedef struct rpmmap_s {
       const char * fn;
  @@ -105,21 +108,22 @@
   	 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
  +	if (_display) {
  +	    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);
  +      }
  +      {
   	const char * type;
   	const char * name;
   	char * b;
  @@ -167,7 +171,7 @@
   	    map->np = nb;
   	} else
   	    continue;
  -#endif
  +      }
       }
       if (map->i) {
   	xar_iter_free(map->i);
  @@ -180,21 +184,217 @@
       return map;
   }
   
  +#ifdef	NOTYET
  +static struct {
  +	const char *name;
  +	mode_t type;
  +} filetypes [] = {
  +	{ "file", S_IFREG },
  +	{ "directory", S_IFDIR },
  +	{ "symlink", S_IFLNK },
  +	{ "fifo", S_IFIFO },
  +	{ "character special", S_IFCHR },
  +	{ "block special", S_IFBLK },
  +	{ "socket", S_IFSOCK },
  +#ifdef S_IFWHT
  +	{ "whiteout", S_IFWHT },
  +#endif
  +	{ NULL, 0 }
  +};
  +
  +static const char * filetype_name (mode_t mode) {
  +	unsigned int i;
  +	for (i = 0; filetypes[i].name; i++)
  +		if (mode == filetypes[i].type)
  +			return (filetypes[i].name);
  +	return ("unknown");
  +}
  +
  +static void x_addtime(xar_file_t f, const char * key, const time_t * timep)
  +{
  +    char time[128];
  +    struct tm t;
  +
  +    gmtime_r(timep, &t);
  +    memset(time, 0, sizeof(time));
  +    strftime(time, sizeof(time), "%FT%T", &t);
  +    strcat(time, "Z");
  +    xar_prop_set(f, key, time);
  +}
  +
  +int32_t _xar_stat_archive(xar_t x, xar_file_t f, const char *file, const char *buffer, size_t len, struct stat *st);
  +int32_t _xar_stat_archive(xar_t x, xar_file_t f, const char *file, const char *buffer, size_t len, struct stat *st)
  +{
  +	char *tmpstr;
  +	struct passwd *pw;
  +	struct group *gr;
  +	const char *type;
  +
  +#ifdef	IGNORE
  +	/* no stat attributes for data from a buffer, it is just a file */
  +	if(len){
  +		xar_prop_set(f, "type", "file");
  +		return 0;
  +	}
  +	
  +	if( S_ISREG(st->st_mode) && (st->st_nlink > 1) ) {
  +		xar_file_t tmpf;
  +		const char *id = xar_attr_get(f, NULL, "id");
  +		if( !id ) {
  +			xar_err_new(x);
  +			xar_err_set_file(x, f);
  +			xar_err_set_string(x, "stat: No file id for file");
  +			xar_err_callback(x, XAR_SEVERITY_NONFATAL, XAR_ERR_ARCHIVE_CREATION);
  +			return -1;
  +		}
  +		tmpf = xar_link_lookup(x, st->st_dev, st->st_ino, f);
  +		xar_prop_set(f, "type", "hardlink");
  +		if( tmpf ) {
  +			const char *id;
  +			id = xar_attr_get(tmpf, NULL, "id");
  +			xar_attr_set(f, "type", "link", id);
  +		} else {
  +			xar_attr_set(f, "type", "link", "original");
  +		}
  +	} else
  +#endif
  +	{
  +		type = filetype_name(st->st_mode & S_IFMT);
  +		xar_prop_set(f, "type", type);
  +	}
  +
  +#ifdef	IGNORE
  +	/* Record major/minor device node numbers */
  +	if( S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) {
  +		uint32_t major, minor;
  +		char tmpstr[12];
  +		xar_devmake(st->st_rdev, &major, &minor);
  +		memset(tmpstr, 0, sizeof(tmpstr));
  +		snprintf(tmpstr, sizeof(tmpstr)-1, "%u", major);
  +		xar_prop_set(f, "device/major", tmpstr);
  +		memset(tmpstr, 0, sizeof(tmpstr));
  +		snprintf(tmpstr, sizeof(tmpstr)-1, "%u", minor);
  +		xar_prop_set(f, "device/minor", tmpstr);
  +	}
  +
  +	if( S_ISLNK(st->st_mode) ) {
  +		char link[4096];
  +		struct stat lsb;
  +
  +		memset(link, 0, sizeof(link));
  +		readlink(file, link, sizeof(link)-1);
  +		xar_prop_set(f, "link", link);
  +		if( stat(file, &lsb) != 0 ) {
  +			xar_attr_set(f, "link", "type", "broken");
  +		} else {
  +			type = filetype_name(lsb.st_mode & S_IFMT);
  +			xar_attr_set(f, "link", "type", type);
  +		}
  +	}
  +#endif
  +
  +	asprintf(&tmpstr, "%04o", st->st_mode & (~S_IFMT));
  +	xar_prop_set(f, "mode", tmpstr);
  +	free(tmpstr);
  +
  +	asprintf(&tmpstr, "%"PRIu64, (uint64_t)st->st_uid);
  +	xar_prop_set(f, "uid", tmpstr);
  +	free(tmpstr);
  +
  +	pw = getpwuid(st->st_uid);
  +	if( pw )
  +		xar_prop_set(f, "user", pw->pw_name);
  +
  +	asprintf(&tmpstr, "%"PRIu64, (uint64_t)st->st_gid);
  +	xar_prop_set(f, "gid", tmpstr);
  +	free(tmpstr);
  +
  +	gr = getgrgid(st->st_gid);
  +	if( gr )
  +		xar_prop_set(f, "group", gr->gr_name);
  +
  +	x_addtime(f, "atime", &st->st_atime);
  +
  +	x_addtime(f, "mtime", &st->st_mtime);
  +
  +	x_addtime(f, "ctime", &st->st_ctime);
  +
  +#ifdef	IGNORE
  +	flags_archive(f, st);
  +
  +	aacls(f, file);
  +#endif
  +
  +	return 0;
  +}
  +#endif
  +
   static int wrXARbuffer(rpmmap map, const char * fn, char * b, size_t nb)
   {
       if (b && nb > 0) {
  -	char val[32];
  +	struct stat sb, *st = &sb;
  +	time_t now = time(NULL);
  +
  +	if (_explode) {
  +	    FD_t fd = Fopen(fn, "w");
  +
  +	    if (fd) {
  +		(void) Fwrite(b, 1, nb, fd);
  +		(void) Fclose(fd);
  +	    }
  +	}
  +
  +	memset(st, 0, sizeof(*st));
  +	st->st_dev = 0;
  +	st->st_ino = 0;
  +	st->st_mode = S_IFREG | 0644;
  +	st->st_nlink = 1;
  +	st->st_uid = 0;
  +	st->st_gid = 0;
  +	st->st_rdev = 0;
  +	st->st_size = nb;
  +	st->st_blksize = 0;
  +	st->st_blocks = 0;
  +	st->st_atime = now;
  +	st->st_mtime = now;
  +	st->st_ctime = now;
  +
  +#ifdef	NOTYET	/* xar-1.5.1 patching needed. */
  +	xar_set_stat(map->x, st);
  +#endif
  +
   	map->f = xar_add_frombuffer(map->x, NULL, fn, b, nb);
   	if (map->f == NULL)
   	    return 1;
  -	xar_prop_set(map->f, "uid", "0");
  -	xar_prop_set(map->f, "gid", "0");
  +
  +#ifdef	NOTYET
   	xar_prop_set(map->f, "mode", "00644");
  +	xar_prop_set(map->f, "uid", "0");
   	xar_prop_set(map->f, "user", "root");
  +	xar_prop_set(map->f, "gid", "0");
   	xar_prop_set(map->f, "group", "root");
  -	snprintf(val, sizeof(val), "%llu", (unsigned long long)nb);
  -	xar_prop_set(map->f, "size", val);
  -	xar_prop_set(map->f, "data/size", val);
  +
  +	x_addtime(map->f, "atime", &now);
  +	x_addtime(map->f, "mtime", &now);
  +	x_addtime(map->f, "ctime", &now);
  +
  +#if 0
  +	xar_prop_set(map->f, "data", NULL);
  +	xar_prop_set(map->f, "data/extracted-checksum", NULL);
  +	xar_prop_set(map->f, "data/archived-checksum", NULL);
  +	xar_prop_set(map->f, "data/encoding", NULL);
  +#endif
  +
  +	{   char val[32];
  +	    snprintf(val, sizeof(val), "%llu", (unsigned long long)nb);
  +	    xar_prop_set(map->f, "data/size", val);
  +	}
  +
  +#if 0
  +	xar_prop_set(map->f, "data/offset", NULL);
  +	xar_prop_set(map->f, "data/length", NULL);
  +#endif
  +#endif
       }
       return 0;
   }
  @@ -266,6 +466,10 @@
   static struct poptOption optionsTable[] = {
    { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN,		&_debug, 1,
   	NULL, NULL },
  + { "display", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN,	&_display, 1,
  +	NULL, NULL },
  + { "explode", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN,	&_explode, 1,
  +	NULL, NULL },
   
    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
   	N_("Common options:"),
  @@ -282,7 +486,7 @@
       poptContext optCon = rpmcliInit(argc, argv, optionsTable);
       int ret = 0;
       rpmmap map;
  -    const char * rpmfn = "time-1.7-22.i386.rpm";
  +    const char * rpmfn = "time-1.7-29.i386.rpm";
       const char * xarfn = "time.xar";
   
       if (optCon == NULL)
  @@ .
Received on Wed Aug 29 22:39:55 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.