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