rpm 5.2.1

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

- File List
- Globals

rpm2cpio.c
Go to the documentation of this file.
1 /* rpmarchive: spit out the main archive portion of a package */
2
3 #include "system.h"
4 const char *__progname;
5
6 #include <rpmio.h>
7 #include <rpmiotypes.h> /* XXX fnpyKey */
8 #include <rpmurl.h>
9 #include <rpmtypes.h>
10 #include <rpmtag.h>
11 #include <pkgio.h>
12
13 #include <rpmts.h>
14
15 #include "debug.h"
16
17 int main(int argc, char **argv)
18 {
19 FD_t fdi, fdo;
20 Header h;
21 char * rpmio_flags;
22 rpmRC rc;
23 FD_t gzdi;
24
25 setprogname(argv[0]); /* Retrofit glibc __progname */
26 if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-")))
27 fdi = fdDup(STDIN_FILENO);
28 else {
29 int ut = urlPath(argv[1], NULL);
30 if (ut == URL_IS_HTTP || ut == URL_IS_HTTPS) {
31 fprintf(stderr, "%s: %s: HTTP/HTTPS transport is non-functional.\n",
32 argv[0], argv[1]);
33 exit(EXIT_FAILURE);
34 }
35 fdi = Fopen(argv[1], "r");
36 }
37
38 if (Ferror(fdi)) {
39 fprintf(stderr, "%s: %s: %s\n", argv[0],
40 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
41 exit(EXIT_FAILURE);
42 }
43 fdo = fdDup(STDOUT_FILENO);
44
45 { rpmts ts = rpmtsCreate();
46 rpmVSFlags vsflags = 0;
47
48 /* XXX retain the ageless behavior of rpm2cpio */
49 vsflags |= _RPMVSF_NODIGESTS;
50 vsflags |= _RPMVSF_NOSIGNATURES;
51 vsflags |= RPMVSF_NOHDRCHK;
52 (void) rpmtsSetVSFlags(ts, vsflags);
53
54 /*@-mustmod@*/ /* LCL: segfault */
55 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
56 /*@=mustmod@*/
57
58 (void)rpmtsFree(ts);
59 ts = NULL;
60 }
61
62 switch (rc) {
63 case RPMRC_OK:
64 case RPMRC_NOKEY:
65 case RPMRC_NOTTRUSTED:
66 break;
67 case RPMRC_NOTFOUND:
68 fprintf(stderr, _("argument is not an RPM package\n"));
69 exit(EXIT_FAILURE);
70 break;
71 case RPMRC_FAIL:
72 default:
73 fprintf(stderr, _("error reading header from package\n"));
74 exit(EXIT_FAILURE);
75 break;
76 }
77
78 /* Retrieve type of payload compression. */
79 { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
80 const char * payload_compressor = NULL;
81 char * t;
82 int xx;
83
84 he->tag = RPMTAG_PAYLOADCOMPRESSOR;
85 xx = headerGet(h, he, 0);
86 payload_compressor = (xx ? he->p.str : "gzip");
87
88 rpmio_flags = t = alloca(sizeof("r.gzdio"));
89 *t++ = 'r';
90 if (!strcmp(payload_compressor, "gzip"))
91 t = stpcpy(t, ".gzdio");
92 if (!strcmp(payload_compressor, "bzip2"))
93 t = stpcpy(t, ".bzdio");
94 if (!strcmp(payload_compressor, "lzma"))
95 t = stpcpy(t, ".lzdio");
96 if (!strcmp(payload_compressor, "xz"))
97 t = stpcpy(t, ".xzdio");
98 he->p.ptr = _free(he->p.ptr);
99 }
100
101 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
102 if (gzdi == NULL) {
103 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
104 exit(EXIT_FAILURE);
105 }
106
107 rc = ufdCopy(gzdi, fdo);
108 rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
109 Fclose(fdo);
110
111 Fclose(gzdi); /* XXX gzdi == fdi */
112
113 return rc;
114 }