1996-03-03 01:36:57 +08:00
|
|
|
/* rpmarchive: spit out the main archive portion of a package */
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
2005-01-18 07:58:09 +08:00
|
|
|
const char *__progname;
|
1998-07-26 05:00:26 +08:00
|
|
|
|
2001-10-26 12:16:19 +08:00
|
|
|
#include <rpmlib.h>
|
|
|
|
#include <rpmpgp.h>
|
|
|
|
|
|
|
|
#include "depends.c"
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-03-03 01:36:57 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fdi, fdo;
|
1999-11-15 03:15:18 +08:00
|
|
|
Header h;
|
2000-06-23 09:19:45 +08:00
|
|
|
char * rpmio_flags;
|
2001-10-26 12:16:19 +08:00
|
|
|
rpmRC rc;
|
1998-11-23 03:48:48 +08:00
|
|
|
FD_t gzdi;
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1999-09-26 23:04:03 +08:00
|
|
|
setprogname(argv[0]); /* Retrofit glibc __progname */
|
2001-06-18 06:18:03 +08:00
|
|
|
if (argc == 1)
|
1998-11-20 02:10:28 +08:00
|
|
|
fdi = fdDup(STDIN_FILENO);
|
2001-06-18 06:18:03 +08:00
|
|
|
else
|
1999-11-05 05:26:08 +08:00
|
|
|
fdi = Fopen(argv[1], "r.ufdio");
|
1996-03-03 01:36:57 +08:00
|
|
|
|
2001-06-18 06:18:03 +08:00
|
|
|
if (Ferror(fdi)) {
|
|
|
|
fprintf(stderr, "%s: %s: %s\n", argv[0],
|
|
|
|
(argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
1998-11-20 02:10:28 +08:00
|
|
|
fdo = fdDup(STDOUT_FILENO);
|
1996-03-03 01:36:57 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
{ rpmts ts = rpmtsCreate();
|
2002-08-06 09:41:44 +08:00
|
|
|
rpmVSFlags vsflags = 0;
|
2002-07-26 07:36:32 +08:00
|
|
|
|
|
|
|
/* XXX retain the ageless behavior of rpm2cpio */
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
|
|
|
vsflags |= RPMVSF_NOHDRCHK;
|
|
|
|
(void) rpmtsSetVSFlags(ts, vsflags);
|
2001-10-28 04:09:20 +08:00
|
|
|
|
2007-09-12 01:04:11 +08:00
|
|
|
/* LCL: segfault */
|
2001-10-26 12:16:19 +08:00
|
|
|
rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
|
|
|
|
|
2002-05-17 00:55:21 +08:00
|
|
|
ts = rpmtsFree(ts);
|
2001-10-26 12:16:19 +08:00
|
|
|
}
|
|
|
|
|
1998-11-23 03:48:48 +08:00
|
|
|
switch (rc) {
|
2001-10-26 12:16:19 +08:00
|
|
|
case RPMRC_OK:
|
2002-08-24 05:01:59 +08:00
|
|
|
case RPMRC_NOKEY:
|
|
|
|
case RPMRC_NOTTRUSTED:
|
1998-11-23 03:48:48 +08:00
|
|
|
break;
|
2002-05-05 04:13:14 +08:00
|
|
|
case RPMRC_NOTFOUND:
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("argument is not an RPM package\n"));
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1998-11-23 03:48:48 +08:00
|
|
|
break;
|
2001-10-26 12:16:19 +08:00
|
|
|
case RPMRC_FAIL:
|
1998-11-23 03:48:48 +08:00
|
|
|
default:
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("error reading header from package\n"));
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1998-11-23 03:48:48 +08:00
|
|
|
break;
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
|
|
|
|
2000-06-23 09:19:45 +08:00
|
|
|
/* Retrieve type of payload compression. */
|
|
|
|
{ const char * payload_compressor = NULL;
|
|
|
|
char * t;
|
|
|
|
|
|
|
|
if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
|
|
|
|
(void **) &payload_compressor, NULL))
|
|
|
|
payload_compressor = "gzip";
|
|
|
|
rpmio_flags = t = alloca(sizeof("r.gzdio"));
|
|
|
|
*t++ = 'r';
|
|
|
|
if (!strcmp(payload_compressor, "gzip"))
|
|
|
|
t = stpcpy(t, ".gzdio");
|
|
|
|
if (!strcmp(payload_compressor, "bzip2"))
|
|
|
|
t = stpcpy(t, ".bzdio");
|
|
|
|
}
|
|
|
|
|
|
|
|
gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
|
2000-12-03 05:53:44 +08:00
|
|
|
if (gzdi == NULL) {
|
1999-11-15 03:15:18 +08:00
|
|
|
fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1999-11-15 03:15:18 +08:00
|
|
|
rc = ufdCopy(gzdi, fdo);
|
|
|
|
rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
|
|
Fclose(fdo);
|
1996-12-12 11:21:00 +08:00
|
|
|
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(gzdi); /* XXX gzdi == fdi */
|
1996-12-12 11:21:00 +08:00
|
|
|
|
1998-11-23 03:48:48 +08:00
|
|
|
return rc;
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|