rpm 5.2.1
|
00001 /* rpmarchive: spit out the main archive portion of a package */ 00002 00003 #include "system.h" 00004 const char *__progname; 00005 00006 #include <rpmio.h> 00007 #include <rpmiotypes.h> /* XXX fnpyKey */ 00008 #include <rpmurl.h> 00009 #include <rpmtypes.h> 00010 #include <rpmtag.h> 00011 #include <pkgio.h> 00012 00013 #include <rpmts.h> 00014 00015 #include "debug.h" 00016 00017 int main(int argc, char **argv) 00018 { 00019 FD_t fdi, fdo; 00020 Header h; 00021 char * rpmio_flags; 00022 rpmRC rc; 00023 FD_t gzdi; 00024 00025 setprogname(argv[0]); /* Retrofit glibc __progname */ 00026 if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) 00027 fdi = fdDup(STDIN_FILENO); 00028 else { 00029 int ut = urlPath(argv[1], NULL); 00030 if (ut == URL_IS_HTTP || ut == URL_IS_HTTPS) { 00031 fprintf(stderr, "%s: %s: HTTP/HTTPS transport is non-functional.\n", 00032 argv[0], argv[1]); 00033 exit(EXIT_FAILURE); 00034 } 00035 fdi = Fopen(argv[1], "r"); 00036 } 00037 00038 if (Ferror(fdi)) { 00039 fprintf(stderr, "%s: %s: %s\n", argv[0], 00040 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi)); 00041 exit(EXIT_FAILURE); 00042 } 00043 fdo = fdDup(STDOUT_FILENO); 00044 00045 { rpmts ts = rpmtsCreate(); 00046 rpmVSFlags vsflags = 0; 00047 00048 /* XXX retain the ageless behavior of rpm2cpio */ 00049 vsflags |= _RPMVSF_NODIGESTS; 00050 vsflags |= _RPMVSF_NOSIGNATURES; 00051 vsflags |= RPMVSF_NOHDRCHK; 00052 (void) rpmtsSetVSFlags(ts, vsflags); 00053 00054 /*@-mustmod@*/ /* LCL: segfault */ 00055 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h); 00056 /*@=mustmod@*/ 00057 00058 (void)rpmtsFree(ts); 00059 ts = NULL; 00060 } 00061 00062 switch (rc) { 00063 case RPMRC_OK: 00064 case RPMRC_NOKEY: 00065 case RPMRC_NOTTRUSTED: 00066 break; 00067 case RPMRC_NOTFOUND: 00068 fprintf(stderr, _("argument is not an RPM package\n")); 00069 exit(EXIT_FAILURE); 00070 break; 00071 case RPMRC_FAIL: 00072 default: 00073 fprintf(stderr, _("error reading header from package\n")); 00074 exit(EXIT_FAILURE); 00075 break; 00076 } 00077 00078 /* Retrieve type of payload compression. */ 00079 { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); 00080 const char * payload_compressor = NULL; 00081 char * t; 00082 int xx; 00083 00084 he->tag = RPMTAG_PAYLOADCOMPRESSOR; 00085 xx = headerGet(h, he, 0); 00086 payload_compressor = (xx ? he->p.str : "gzip"); 00087 00088 rpmio_flags = t = alloca(sizeof("r.gzdio")); 00089 *t++ = 'r'; 00090 if (!strcmp(payload_compressor, "gzip")) 00091 t = stpcpy(t, ".gzdio"); 00092 if (!strcmp(payload_compressor, "bzip2")) 00093 t = stpcpy(t, ".bzdio"); 00094 if (!strcmp(payload_compressor, "lzma")) 00095 t = stpcpy(t, ".lzdio"); 00096 if (!strcmp(payload_compressor, "xz")) 00097 t = stpcpy(t, ".xzdio"); 00098 he->p.ptr = _free(he->p.ptr); 00099 } 00100 00101 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */ 00102 if (gzdi == NULL) { 00103 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi)); 00104 exit(EXIT_FAILURE); 00105 } 00106 00107 rc = ufdCopy(gzdi, fdo); 00108 rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS; 00109 Fclose(fdo); 00110 00111 Fclose(gzdi); /* XXX gzdi == fdi */ 00112 00113 return rc; 00114 }