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
|
|
|
|
2008-01-30 19:53:51 +08:00
|
|
|
#include <rpm/rpmlib.h> /* rpmReadPackageFile .. */
|
|
|
|
#include <rpm/rpmtag.h>
|
|
|
|
#include <rpm/rpmio.h>
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmpgp.h>
|
2001-10-26 12:16:19 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmts.h>
|
2001-10-26 12:16:19 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1996-03-03 01:36:57 +08:00
|
|
|
|
2007-09-18 11:53:37 +08:00
|
|
|
int main(int argc, char *argv[])
|
1996-03-03 01:36:57 +08:00
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fdi, fdo;
|
1999-11-15 03:15:18 +08:00
|
|
|
Header h;
|
2009-08-31 15:19:45 +08:00
|
|
|
char * rpmio_flags = NULL;
|
2010-09-21 16:37:21 +08:00
|
|
|
int 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 */
|
2009-09-15 17:57:51 +08:00
|
|
|
rpmReadConfigFiles(NULL, NULL);
|
2001-06-18 06:18:03 +08:00
|
|
|
if (argc == 1)
|
1998-11-20 02:10:28 +08:00
|
|
|
fdi = fdDup(STDIN_FILENO);
|
2009-06-18 19:52:45 +08:00
|
|
|
else {
|
2009-08-31 17:55:33 +08:00
|
|
|
if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
|
2009-06-18 19:52:45 +08:00
|
|
|
fprintf(stderr, "Usage: rpm2cpio file.rpm\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
1999-11-05 05:26:08 +08:00
|
|
|
fdi = Fopen(argv[1], "r.ufdio");
|
2009-06-18 19:52:45 +08:00
|
|
|
}
|
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
|
|
|
|
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. */
|
2009-09-02 18:06:25 +08:00
|
|
|
{ const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
|
2009-08-31 15:19:45 +08:00
|
|
|
rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
|
2000-06-23 09:19:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
|
2009-08-31 15:19:45 +08:00
|
|
|
free(rpmio_flags);
|
|
|
|
|
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
|
|
|
}
|