rpm 4.10.90

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpm2cpio.c
Go to the documentation of this file.

    00001 /* rpmarchive: spit out the main archive portion of a package */
    00002
    00003 #include "system.h"
    00004 const char *__progname;
    00005
    00006 #include <rpm/rpmlib.h>         /* rpmReadPackageFile .. */
    00007 #include <rpm/rpmtag.h>
    00008 #include <rpm/rpmio.h>
    00009 #include <rpm/rpmpgp.h>
    00010
    00011 #include <rpm/rpmts.h>
    00012
    00013 #include "debug.h"
    00014
    00015 int main(int argc, char *argv[])
    00016 {
    00017     FD_t fdi, fdo;
    00018     Header h;
    00019     char * rpmio_flags = NULL;
    00020     int rc;
    00021     off_t payload_size;
    00022     FD_t gzdi;
    00023
    00024     setprogname(argv[0]);       /* Retrofit glibc __progname */
    00025     rpmReadConfigFiles(NULL, NULL);
    00026     if (argc == 1)
    00027         fdi = fdDup(STDIN_FILENO);
    00028     else {
    00029         if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
    00030             fprintf(stderr, "Usage: rpm2cpio file.rpm\n");
    00031             exit(EXIT_FAILURE);
    00032         }
    00033         fdi = Fopen(argv[1], "r.ufdio");
    00034     }
    00035
    00036     if (Ferror(fdi)) {
    00037         fprintf(stderr, "%s: %s: %s\n", argv[0],
    00038                 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
    00039         exit(EXIT_FAILURE);
    00040     }
    00041     fdo = fdDup(STDOUT_FILENO);
    00042
    00043     {   rpmts ts = rpmtsCreate();
    00044         rpmVSFlags vsflags = 0;
    00045
    00046         /* XXX retain the ageless behavior of rpm2cpio */
    00047         vsflags |= _RPMVSF_NODIGESTS;
    00048         vsflags |= _RPMVSF_NOSIGNATURES;
    00049         vsflags |= RPMVSF_NOHDRCHK;
    00050         (void) rpmtsSetVSFlags(ts, vsflags);
    00051
    00052         rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
    00053
    00054         ts = rpmtsFree(ts);
    00055     }
    00056
    00057     switch (rc) {
    00058     case RPMRC_OK:
    00059     case RPMRC_NOKEY:
    00060     case RPMRC_NOTTRUSTED:
    00061         break;
    00062     case RPMRC_NOTFOUND:
    00063         fprintf(stderr, _("argument is not an RPM package\n"));
    00064         exit(EXIT_FAILURE);
    00065         break;
    00066     case RPMRC_FAIL:
    00067     default:
    00068         fprintf(stderr, _("error reading header from package\n"));
    00069         exit(EXIT_FAILURE);
    00070         break;
    00071     }
    00072
    00073     /* Retrieve payload size and compression type. */
    00074     {   const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
    00075         rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
    00076         payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
    00077     }
    00078
    00079     gzdi = Fdopen(fdi, rpmio_flags);    /* XXX gzdi == fdi */
    00080     free(rpmio_flags);
    00081
    00082     if (gzdi == NULL) {
    00083         fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
    00084         exit(EXIT_FAILURE);
    00085     }
    00086
    00087     rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE;
    00088
    00089     Fclose(fdo);
    00090
    00091     Fclose(gzdi);       /* XXX gzdi == fdi */
    00092
    00093     return rc;
    00094 }