]> git.pld-linux.org Git - packages/rpm.git/blame - rpm-lzma2.patch
- debugcflags -= -feliminate-dwarf2-dups disabled until PR ld/3290 is fixed.
[packages/rpm.git] / rpm-lzma2.patch
CommitLineData
73b98840 1diff -Nru rpm-4.4.5.old/build/pack.c rpm-4.4.5/build/pack.c
2--- rpm-4.4.5.old/build/pack.c 2005-12-09 11:07:42.000000000 +0100
3+++ rpm-4.4.5/build/pack.c 2006-04-22 22:00:58.000000000 +0200
4@@ -499,6 +499,12 @@
5 /* Add prereq on rpm version that understands bzip2 payloads */
6 (void) rpmlibNeedsFeature(h, "PayloadIsBzip2", "3.0.5-1");
7 }
8+ if (s[1] == 'l' && s[2] == 'z') {
9+ (void) headerAddEntry(h, RPMTAG_PAYLOADCOMPRESSOR, RPM_STRING_TYPE,
10+ "lzma", 1);
11+ (void) rpmlibNeedsFeature(h, "PayloadIsLzma", "4.4.6-1");
12+ }
13+
14 strcpy(buf, rpmio_flags);
15 buf[s - rpmio_flags] = '\0';
16 (void) headerAddEntry(h, RPMTAG_PAYLOADFLAGS, RPM_STRING_TYPE, buf+1, 1);
17diff -Nru rpm-4.4.5.old/lib/psm.c rpm-4.4.5/lib/psm.c
18--- rpm-4.4.5.old/lib/psm.c 2006-04-22 15:02:52.000000000 +0200
19+++ rpm-4.4.5/lib/psm.c 2006-04-22 17:18:55.000000000 +0200
20@@ -2154,6 +2154,8 @@
21 t = stpcpy(t, ".gzdio");
22 if (!strcmp(payload_compressor, "bzip2"))
23 t = stpcpy(t, ".bzdio");
24+ if (!strcmp(payload_compressor, "lzma"))
25+ t = stpcpy(t, ".lzdio");
26
27 /*@-branchstate@*/
28 if (!hge(fi->h, RPMTAG_PAYLOADFORMAT, NULL,
29diff -Nru rpm-4.4.5.old/lib/rpmds.c rpm-4.4.5/lib/rpmds.c
30--- rpm-4.4.5.old/lib/rpmds.c 2005-12-09 10:52:23.000000000 +0100
31+++ rpm-4.4.5/lib/rpmds.c 2006-04-22 22:04:23.000000000 +0200
32@@ -1324,6 +1324,9 @@
33 { "rpmlib(PayloadIsUstar)", "4.4.4-1",
34 (RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
35 N_("package payload can be in ustar tar archive format.") },
36+ { "rpmlib(PayloadIsLzma)", "4.4.6-1",
37+ (RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
38+ N_("package payload can be compressed using lzma.") },
39 { NULL, NULL, 0, NULL }
40 };
41
42diff -Nru rpm-4.4.5.old/rpm2cpio.c rpm-4.4.5/rpm2cpio.c
43--- rpm-4.4.5.old/rpm2cpio.c 2005-01-17 19:46:16.000000000 +0100
44+++ rpm-4.4.5/rpm2cpio.c 2006-04-22 17:18:55.000000000 +0200
45@@ -76,6 +76,8 @@
46 t = stpcpy(t, ".gzdio");
47 if (!strcmp(payload_compressor, "bzip2"))
48 t = stpcpy(t, ".bzdio");
49+ if (!strcmp(payload_compressor, "lzma"))
50+ t = stpcpy(t, ".lzdio");
51 }
52
53 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
54diff -Nru rpm-4.4.5.old/rpmio/librpmio.vers rpm-4.4.5/rpmio/librpmio.vers
55--- rpm-4.4.5.old/rpmio/librpmio.vers 2005-11-01 14:37:40.000000000 +0100
56+++ rpm-4.4.5/rpmio/librpmio.vers 2006-04-22 17:18:55.000000000 +0200
57@@ -85,6 +85,7 @@
58 isCompressed;
59 Link;
60 Lstat;
61+ lzdio;
62 max_macro_depth;
63 Mkdir;
64 noLibio;
65diff -Nru rpm-4.4.5.old/rpmio/Makefile.am rpm-4.4.5/rpmio/Makefile.am
66--- rpm-4.4.5.old/rpmio/Makefile.am 2006-04-22 15:02:56.000000000 +0200
67+++ rpm-4.4.5/rpmio/Makefile.am 2006-04-23 13:31:09.000000000 +0200
68@@ -22,14 +22,14 @@
2e804dec 69 argv.h fts.h rmd128.h rmd160.h rpmdav.h \
73b98840 70 rpmio.h rpmurl.h rpmmacro.h rpmlog.h rpmmessages.h rpmerr.h rpmpgp.h \
71 rpmsq.h rpmsw.h ugid.h
72-noinst_HEADERS = rpmio_internal.h rpmlua.h rpmhook.h
73+noinst_HEADERS = LzmaDecode.h rpmio_internal.h rpmlua.h rpmhook.h
74
75 BEECRYPTLOBJS = $(shell test X"@WITH_BEECRYPT_SUBDIR@" != X && cat $(top_builddir)/@WITH_BEECTYPT_SUBDIR@/listobjs)
76
77 usrlibdir = $(libdir)@MARK64@
78 usrlib_LTLIBRARIES = librpmio.la
79 librpmio_la_SOURCES = \
2e804dec 80- argv.c digest.c fts.c macro.c rmd128.c rmd160.c rpmdav.c \
81+ LzmaDecode.c argv.c digest.c fts.c macro.c rmd128.c rmd160.c rpmdav.c \
73b98840 82 rpmhook.c rpmio.c rpmlog.c rpmlua.c rpmmalloc.c \
83 rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c strtolocale.c \
84 stubs.c url.c ugid.c
85diff -Nru rpm-4.4.5.old/rpmio/rpmio.c rpm-4.4.5/rpmio/rpmio.c
86--- rpm-4.4.5.old/rpmio/rpmio.c 2006-04-22 15:02:55.000000000 +0200
87+++ rpm-4.4.5/rpmio/rpmio.c 2006-04-23 14:43:10.000000000 +0200
88@@ -82,6 +82,7 @@
89 #define FDONLY(fd) assert(fdGetIo(fd) == fdio)
90 #define GZDONLY(fd) assert(fdGetIo(fd) == gzdio)
91 #define BZDONLY(fd) assert(fdGetIo(fd) == bzdio)
92+#define LZDONLY(fd) assert(fdGetIo(fd) == lzdio)
93
94 #define UFDONLY(fd) /* assert(fdGetIo(fd) == ufdio) */
95
96@@ -182,6 +183,8 @@
97 } else if (fps->io == bzdio) {
98 sprintf(be, "BZD %p fdno %d", fps->fp, fps->fdno);
99 #endif
100+ } else if (fps->io == lzdio) {
101+ sprintf(be, "LZD %p fdno %d", fps->fp, fps->fdno);
102 } else if (fps->io == fpio) {
103 /*@+voidabstract@*/
104 sprintf(be, "%s %p(%d) fdno %d",
105@@ -2370,6 +2373,327 @@
106 /*@=moduncon@*/
107 #endif /* HAVE_BZLIB_H */
108
109+#include "LzmaDecode.h"
110+
111+#define kInBufferSize (1 << 15)
112+typedef struct _CBuffer
113+{
114+ ILzmaInCallback InCallback;
115+ FILE *File;
116+ unsigned char Buffer[kInBufferSize];
117+} CBuffer;
118+
119+typedef struct lzfile {
120+ CBuffer g_InBuffer;
121+ CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */
122+ unsigned char properties[LZMA_PROPERTIES_SIZE];
123+
124+// FILE *file;
125+ int pid;
126+} LZFILE;
127+
128+static size_t MyReadFile(FILE *file, void *data, size_t size)
129+{
130+ if (size == 0) return 0;
131+ return fread(data, 1, size, file);
132+}
133+
134+static int MyReadFileAndCheck(FILE *file, void *data, size_t size)
135+{
136+ return (MyReadFile(file, data, size) == size);
137+}
138+
139+static int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
140+{
141+ CBuffer *b = (CBuffer *)object;
142+ *buffer = b->Buffer;
143+ *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);
144+ return LZMA_RESULT_OK;
145+}
146+
147+static inline /*@dependent@*/ void * lzdFileno(FD_t fd)
148+ /*@*/
149+{
150+ void * rc = NULL;
151+ int i;
152+
153+ FDSANE(fd);
154+ for (i = fd->nfps; i >= 0; i--) {
155+/*@-boundsread@*/
156+ FDSTACK_t * fps = &fd->fps[i];
157+/*@=boundsread@*/
158+ if (fps->io != lzdio)
159+ continue;
160+ rc = fps->fp;
161+ break;
162+ }
163+
164+ return rc;
165+}
166+
167+static FD_t lzdWriteOpen(int fdno, int fopen)
168+{
169+ int pid;
170+ int p[2];
171+
172+ if (fdno < 0) return NULL;
173+ if (pipe(p) < 0) {
174+ close(fdno);
175+ return NULL;
176+ }
177+ pid = fork();
178+ if (pid < 0) {
179+ close(fdno);
180+ return NULL;
181+ }
182+ if (pid) {
183+ FD_t fd;
184+ LZFILE *lzfile;
185+
186+ close(fdno);
187+ close(p[0]);
188+ lzfile = calloc(1, sizeof(*lzfile));
189+ if (lzfile == NULL) return NULL;
190+ lzfile->g_InBuffer.File = fdopen(p[1], "wb");
191+ lzfile->pid = pid;
192+ if (lzfile->g_InBuffer.File == NULL) {
193+ close(p[1]);
194+ free(lzfile);
195+ return NULL;
196+ }
197+ fd = fdNew("open (lzdOpen write)");
198+ if (fopen) fdPop(fd);
199+ fdPush(fd, lzdio, lzfile, -1);
200+ return fdLink(fd, "lzdOpen");
201+ } else {
202+ int i;
203+ /* lzma */
204+ close(p[1]);
205+ dup2(p[0], 0);
206+ dup2(fdno, 1);
207+ for (i = 3; i < 1024; i++) close(i);
65189320 208+ if (execl("/usr/bin/lzma", "lzma", "e", "-si", "-so", NULL)) {
73b98840 209+ _exit(1);
210+ }
211+ }
212+ return NULL; /* warning */
213+}
214+
215+static FD_t lzdReadOpen(int fdno, int fopen)
216+{
217+ LZFILE *lzfile;
218+ unsigned char ff[8];
219+ FD_t fd;
220+
221+ if (fdno < 0) return NULL;
222+ lzfile = calloc(1, sizeof(*lzfile));
223+ if (lzfile == NULL) return NULL;
224+ lzfile->g_InBuffer.File = fdopen(fdno, "rb");
225+ if (lzfile->g_InBuffer.File == NULL) goto error2;
226+
227+ if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, lzfile->properties, sizeof(lzfile->properties))) {
228+error:
229+ fclose(lzfile->g_InBuffer.File);
230+error2:
231+ free(lzfile);
232+ return NULL;
233+ }
234+ if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, ff, 8)) goto error;
235+ if (LzmaDecodeProperties(&lzfile->state.Properties, lzfile->properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
236+ goto error;
237+ lzfile->state.Probs = (CProb *)malloc(LzmaGetNumProbs(&lzfile->state.Properties) * sizeof(CProb));
238+ if (lzfile->state.Probs == NULL) goto error;
239+
240+ if (lzfile->state.Properties.DictionarySize == 0)
241+ lzfile->state.Dictionary = 0;
242+ else {
243+ lzfile->state.Dictionary = (unsigned char *)malloc(lzfile->state.Properties.DictionarySize);
244+ if (lzfile->state.Dictionary == NULL) {
245+ free(lzfile->state.Probs);
246+ goto error;
247+ }
248+ }
249+ lzfile->g_InBuffer.InCallback.Read = LzmaReadCompressed;
250+ LzmaDecoderInit(&lzfile->state);
251+
252+ fd = fdNew("open (lzdOpen read)");
253+ if (fopen) fdPop(fd);
254+ fdPush(fd, lzdio, lzfile, -1);
255+ return fdLink(fd, "lzdOpen");
256+}
257+
258+/*@-globuse@*/
259+static /*@null@*/ FD_t lzdOpen(const char * path, const char * mode)
260+ /*@globals fileSystem @*/
261+ /*@modifies fileSystem @*/
262+{
263+ if (mode == NULL)
264+ return NULL;
265+ if (mode[0] == 'w') {
266+ int fdno = open(path, O_WRONLY);
267+
268+ if (fdno < 0) return NULL;
269+ return lzdWriteOpen(fdno, 1);
270+ } else {
271+ int fdno = open(path, O_RDONLY);
272+
273+ if (fdno < 0) return NULL;
274+ return lzdReadOpen(fdno, 1);
275+ }
276+}
277+/*@=globuse@*/
278+
279+/*@-globuse@*/
280+static /*@null@*/ FD_t lzdFdopen(void * cookie, const char * fmode)
281+ /*@globals fileSystem, internalState @*/
282+ /*@modifies fileSystem, internalState @*/
283+{
284+ FD_t fd = c2f(cookie);
285+ int fdno;
286+
287+ if (fmode == NULL) return NULL;
288+ fdno = fdFileno(fd);
289+ fdSetFdno(fd, -1); /* XXX skip the fdio close */
290+ if (fdno < 0) return NULL;
291+ if (fmode[0] == 'w') {
292+ return lzdWriteOpen(fdno, 0);
293+ } else {
294+ return lzdReadOpen(fdno, 0);
295+ }
296+}
297+/*@=globuse@*/
298+
299+/*@-globuse@*/
300+static int lzdFlush(FD_t fd)
301+ /*@globals fileSystem @*/
302+ /*@modifies fileSystem @*/
303+{
304+ LZFILE *lzfile = lzdFileno(fd);
305+
306+ if (lzfile == NULL || lzfile->g_InBuffer.File == NULL) return -2;
307+ return fflush(lzfile->g_InBuffer.File);
308+}
309+/*@=globuse@*/
310+
311+/* =============================================================== */
312+/*@-globuse@*/
313+/*@-mustmod@*/ /* LCL: *buf is modified */
314+static ssize_t lzdRead(void * cookie, /*@out@*/ char * buf, size_t count)
315+ /*@globals fileSystem, internalState @*/
316+ /*@modifies *buf, fileSystem, internalState @*/
317+{
318+ FD_t fd = c2f(cookie);
319+ LZFILE *lzfile;
320+ ssize_t rc = 0;
321+ int res = 0;
322+
323+ if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
324+ lzfile = lzdFileno(fd);
325+ fdstat_enter(fd, FDSTAT_READ);
326+ if (lzfile->g_InBuffer.File)
327+ /*@-compdef@*/
328+ res = LzmaDecode(&lzfile->state, &lzfile->g_InBuffer.InCallback, buf, count, &rc);
329+ /*@=compdef@*/
330+ if (res) {
331+ if (lzfile)
332+ fd->errcookie = "Lzma: decoding error";
333+ } else if (rc >= 0) {
334+ fdstat_exit(fd, FDSTAT_READ, rc);
335+ /*@-compdef@*/
336+ if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
337+ /*@=compdef@*/
338+ }
339+ return rc;
340+}
341+/*@=mustmod@*/
342+/*@=globuse@*/
343+
344+/*@-globuse@*/
345+static ssize_t lzdWrite(void * cookie, const char * buf, size_t count)
346+ /*@globals fileSystem, internalState @*/
347+ /*@modifies fileSystem, internalState @*/
348+{
349+ FD_t fd = c2f(cookie);
350+ LZFILE *lzfile;
351+ ssize_t rc;
352+
353+ if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
354+
355+ if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
356+
357+ lzfile = lzdFileno(fd);
358+ fdstat_enter(fd, FDSTAT_WRITE);
359+ rc = fwrite((void *)buf, 1, count, lzfile->g_InBuffer.File);
360+ if (rc == -1) {
361+ fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
362+ } else if (rc > 0) {
363+ fdstat_exit(fd, FDSTAT_WRITE, rc);
364+ }
365+ return rc;
366+}
367+/*@=globuse@*/
368+
369+static inline int lzdSeek(void * cookie, /*@unused@*/ _libio_pos_t pos,
370+ /*@unused@*/ int whence)
371+ /*@*/
372+{
373+ FD_t fd = c2f(cookie);
374+
375+ LZDONLY(fd);
376+ return -2;
377+}
378+
379+static int lzdClose( /*@only@*/ void * cookie)
380+ /*@globals fileSystem, internalState @*/
381+ /*@modifies fileSystem, internalState @*/
382+{
383+ FD_t fd = c2f(cookie);
384+ LZFILE *lzfile;
385+ int rc;
386+
387+ lzfile = lzdFileno(fd);
388+
389+ if (lzfile == NULL) return -2;
390+ fdstat_enter(fd, FDSTAT_CLOSE);
391+ /*@-noeffectuncon@*/ /* FIX: check rc */
392+ fclose(lzfile->g_InBuffer.File);
393+ if (lzfile->pid) wait4(lzfile->pid, NULL, 0, NULL);
394+ else { /* reading */
395+ free(lzfile->state.Probs);
396+ if (lzfile->state.Dictionary) free(lzfile->state.Dictionary);
397+ }
398+ free(lzfile);
399+ /*@=noeffectuncon@*/
400+ rc = 0; /* XXX FIXME */
401+
402+ /* XXX TODO: preserve fd if errors */
403+
404+ if (fd) {
405+ if (rc == -1) {
406+ fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
407+ } else if (rc >= 0) {
408+ fdstat_exit(fd, FDSTAT_CLOSE, rc);
409+ }
410+ }
411+
412+DBGIO(fd, (stderr, "==>\tlzdClose(%p) rc %lx %s\n", cookie, (unsigned long)rc, fdbg(fd)));
413+
414+ if (_rpmio_debug || rpmIsDebug()) fdstat_print(fd, "LZDIO", stderr);
415+ /*@-branchstate@*/
416+ if (rc == 0)
417+ fd = fdFree(fd, "open (lzdClose)");
418+ /*@=branchstate@*/
419+ return rc;
420+}
421+
422+/*@-type@*/ /* LCL: function typedefs */
423+static struct FDIO_s lzdio_s = {
424+ lzdRead, lzdWrite, lzdSeek, lzdClose, XfdLink, XfdFree, XfdNew, fdFileno,
425+ NULL, lzdOpen, lzdFileno, lzdFlush, NULL, NULL, NULL, NULL, NULL
426+};
427+/*@=type@*/
428+FDIO_t lzdio = /*@-compmempass@*/ &lzdio_s /*@=compmempass@*/ ;
429+
430 /* =============================================================== */
431 /*@observer@*/
432 static const char * getFdErrstr (FD_t fd)
433@@ -2388,7 +2712,9 @@
434 errstr = fd->errcookie;
435 } else
436 #endif /* HAVE_BZLIB_H */
437-
438+ if (fdGetIo(fd) == lzdio) {
439+ errstr = fd->errcookie;
440+ } else
441 {
442 errstr = (fd->syserrno ? strerror(fd->syserrno) : "");
443 }
444@@ -2683,6 +3009,9 @@
445 fd = bzdFdopen(fd, zstdio);
446 /*@=internalglobs@*/
447 #endif
448+ } else if (!strcmp(end, "lzdio")) {
449+ iof = lzdio;
450+ fd = lzdFdopen(fd, zstdio);
451 } else if (!strcmp(end, "ufdio")) {
452 iof = ufdio;
453 } else if (!strcmp(end, "fpio")) {
454@@ -2849,6 +3178,9 @@
455 ec = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0;
456 i--; /* XXX fdio under bzdio always has fdno == -1 */
457 #endif
458+ } else if (fps->io == lzdio) {
459+ ec = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0;
460+ i--; /* XXX fdio under lzdio always has fdno == -1 */
461 } else {
462 /* XXX need to check ufdio/gzdio/bzdio/fdio errors correctly. */
463 ec = (fdFileno(fd) < 0 ? -1 : 0);
464diff -Nru rpm-4.4.5.old/rpmio/rpmio.h rpm-4.4.5/rpmio/rpmio.h
465--- rpm-4.4.5.old/rpmio/rpmio.h 2005-11-04 00:19:54.000000000 +0100
466+++ rpm-4.4.5/rpmio/rpmio.h 2006-04-22 17:18:55.000000000 +0200
467@@ -673,6 +673,10 @@
468
469 /**
470 */
471+/*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
472+
473+/**
474+ */
475 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
476 /*@=exportlocal@*/
477 /*@}*/
478diff -Nru rpm-4.4.5.old/tools/rpmtool.c rpm-4.4.5/tools/rpmtool.c
479--- rpm-4.4.5.old/tools/rpmtool.c 2005-01-17 19:46:27.000000000 +0100
480+++ rpm-4.4.5/tools/rpmtool.c 2006-04-22 17:18:55.000000000 +0200
481@@ -87,7 +87,8 @@
482 RPMIOBITS_UNCOMPRESS= (1 << 8),
483 RPMIOBITS_BINARY = (1 << 9),
484 RPMIOBITS_DUMP = (1 << 10),
485- RPMIOBITS_XML = (1 << 11)
486+ RPMIOBITS_XML = (1 << 11),
487+ RPMIOBITS_LZDIO = (1 << 16),
488 } rpmtoolIOBits;
489
490 static const char * iav[] = { "-", NULL };
491@@ -118,12 +119,13 @@
492 { "gzdio", RPMIOBITS_GZDIO },
493 { "bzdio", RPMIOBITS_BZDIO },
494 #define _RPMIOBITS_MODEMASK \
495- (RPMIOBITS_FDIO|RPMIOBITS_UFDIO|RPMIOBITS_GZDIO|RPMIOBITS_BZDIO)
496+ (RPMIOBITS_FDIO|RPMIOBITS_UFDIO|RPMIOBITS_GZDIO|RPMIOBITS_BZDIO|RPMIOBITS_LZDIO)
497
498 { "uncompress", RPMIOBITS_UNCOMPRESS },
499 { "binary", RPMIOBITS_BINARY },
500 { "dump", RPMIOBITS_DUMP },
501 { "xml", RPMIOBITS_XML },
502+ { "lzdio", RPMIOBITS_LZDIO },
503 { NULL, 0 },
504 };
505
506@@ -450,6 +452,8 @@
507 t = stpcpy(t, ".gzdio");
508 if (!strcmp(payload_compressor, "bzip2"))
509 t = stpcpy(t, ".bzdio");
510+ if (!strcmp(payload_compressor, "lzma"))
511+ t = stpcpy(t, ".lzdio");
512
513 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
514 if (gzdi == NULL) {
This page took 0.134326 seconds and 4 git commands to generate.