Main Page Modules Data Structures File List Data Fields Globals Related Pages

# 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
    00005 #include <rpmlib.h>
    00006 #include <rpmpgp.h>
    00007
    00008 #include "depends.c"
    00009
    00010 #include "debug.h"
    00011
    00012 int main(int argc, char **argv)
    00013 {
    00014     FD_t fdi, fdo;
    00015     Header h;
    00016     char * rpmio_flags;
    00017     rpmRC rc;
    00018     FD_t gzdi;
    00019
    00020     setprogname(argv[0]);       /* Retrofit glibc __progname */
    00021     if (argc == 1)
    00022         fdi = fdDup(STDIN_FILENO);
    00023     else
    00024         fdi = Fopen(argv[1], "r.ufdio");
    00025
    00026     if (Ferror(fdi)) {
    00027         fprintf(stderr, "%s: %s: %s\n", argv[0],
    00028                 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
    00029         exit(EXIT_FAILURE);
    00030     }
    00031     fdo = fdDup(STDOUT_FILENO);
    00032
    00033     {   rpmts ts = rpmtsCreate();
    00034         rpmVSFlags vsflags = 0;
    00035
    00036         /* XXX retain the ageless behavior of rpm2cpio */
    00037         vsflags |= _RPMVSF_NODIGESTS;
    00038         vsflags |= _RPMVSF_NOSIGNATURES;
    00039         vsflags |= RPMVSF_NOHDRCHK;
    00040         (void) rpmtsSetVSFlags(ts, vsflags);
    00041
    00042         /*@-mustmod@*/      /* LCL: segfault */
    00043         rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
    00044         /*@=mustmod@*/
    00045
    00046         ts = rpmtsFree(ts);
    00047     }
    00048
    00049     switch (rc) {
    00050     case RPMRC_OK:
    00051     case RPMRC_NOKEY:
    00052     case RPMRC_NOTTRUSTED:
    00053         break;
    00054     case RPMRC_NOTFOUND:
    00055         fprintf(stderr, _("argument is not an RPM package\n"));
    00056         exit(EXIT_FAILURE);
    00057         break;
    00058     case RPMRC_FAIL:
    00059     default:
    00060         fprintf(stderr, _("error reading header from package\n"));
    00061         exit(EXIT_FAILURE);
    00062         break;
    00063     }
    00064
    00065     /* Retrieve type of payload compression. */
    00066     {   const char * payload_compressor = NULL;
    00067         char * t;
    00068
    00069         if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
    00070                             (void **) &payload_compressor, NULL))
    00071             payload_compressor = "gzip";
    00072         rpmio_flags = t = alloca(sizeof("r.gzdio"));
    00073         *t++ = 'r';
    00074         if (!strcmp(payload_compressor, "gzip"))
    00075             t = stpcpy(t, ".gzdio");
    00076         if (!strcmp(payload_compressor, "bzip2"))
    00077             t = stpcpy(t, ".bzdio");
    00078     }
    00079
    00080     gzdi = Fdopen(fdi, rpmio_flags);    /* XXX gzdi == fdi */
    00081     if (gzdi == NULL) {
    00082         fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
    00083         exit(EXIT_FAILURE);
    00084     }
    00085
    00086     rc = ufdCopy(gzdi, fdo);
    00087     rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
    00088     Fclose(fdo);
    00089
    00090     Fclose(gzdi);       /* XXX gzdi == fdi */
    00091
    00092     return rc;
    00093 }