1 diff -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
5 /* Add prereq on rpm version that understands bzip2 payloads */
6 (void) rpmlibNeedsFeature(h, "PayloadIsBzip2", "3.0.5-1");
8 + if (s[1] == 'l' && s[2] == 'z') {
9 + (void) headerAddEntry(h, RPMTAG_PAYLOADCOMPRESSOR, RPM_STRING_TYPE,
11 + (void) rpmlibNeedsFeature(h, "PayloadIsLzma", "4.4.6-1");
14 strcpy(buf, rpmio_flags);
15 buf[s - rpmio_flags] = '\0';
16 (void) headerAddEntry(h, RPMTAG_PAYLOADFLAGS, RPM_STRING_TYPE, buf+1, 1);
17 diff -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
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");
28 if (!hge(fi->h, RPMTAG_PAYLOADFORMAT, NULL,
29 diff -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
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 }
42 diff -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
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");
53 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
54 diff -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
65 diff -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
69 argv.h fts.h rpmdav.h \
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
75 BEECRYPTLOBJS = $(shell test X"@WITH_BEECRYPT_SUBDIR@" != X && cat $(top_builddir)/@WITH_BEECTYPT_SUBDIR@/listobjs)
77 usrlibdir = $(libdir)@MARK64@
78 usrlib_LTLIBRARIES = librpmio.la
79 librpmio_la_SOURCES = \
80 - argv.c digest.c fts.c macro.c rpmdav.c \
81 + LzmaDecode.c argv.c digest.c fts.c macro.c rpmdav.c \
82 rpmhook.c rpmio.c rpmlog.c rpmlua.c rpmmalloc.c \
83 rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c strtolocale.c \
85 diff -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
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)
94 #define UFDONLY(fd) /* assert(fdGetIo(fd) == ufdio) */
97 } else if (fps->io == bzdio) {
98 sprintf(be, "BZD %p fdno %d", fps->fp, fps->fdno);
100 + } else if (fps->io == lzdio) {
101 + sprintf(be, "LZD %p fdno %d", fps->fp, fps->fdno);
102 } else if (fps->io == fpio) {
104 sprintf(be, "%s %p(%d) fdno %d",
105 @@ -2370,6 +2373,327 @@
107 #endif /* HAVE_BZLIB_H */
109 +#include "LzmaDecode.h"
111 +#define kInBufferSize (1 << 15)
112 +typedef struct _CBuffer
114 + ILzmaInCallback InCallback;
116 + unsigned char Buffer[kInBufferSize];
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];
128 +static size_t MyReadFile(FILE *file, void *data, size_t size)
130 + if (size == 0) return 0;
131 + return fread(data, 1, size, file);
134 +static int MyReadFileAndCheck(FILE *file, void *data, size_t size)
136 + return (MyReadFile(file, data, size) == size);
139 +static int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
141 + CBuffer *b = (CBuffer *)object;
142 + *buffer = b->Buffer;
143 + *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);
144 + return LZMA_RESULT_OK;
147 +static inline /*@dependent@*/ void * lzdFileno(FD_t fd)
154 + for (i = fd->nfps; i >= 0; i--) {
156 + FDSTACK_t * fps = &fd->fps[i];
158 + if (fps->io != lzdio)
167 +static FD_t lzdWriteOpen(int fdno, int fopen)
172 + if (fdno < 0) return NULL;
188 + lzfile = calloc(1, sizeof(*lzfile));
189 + if (lzfile == NULL) return NULL;
190 + lzfile->g_InBuffer.File = fdopen(p[1], "wb");
192 + if (lzfile->g_InBuffer.File == NULL) {
197 + fd = fdNew("open (lzdOpen write)");
198 + if (fopen) fdPop(fd);
199 + fdPush(fd, lzdio, lzfile, -1);
200 + return fdLink(fd, "lzdOpen");
207 + for (i = 3; i < 1024; i++) close(i);
208 + if (execlp("lzma", "lzma", "e", "-si", "-so", NULL)) {
212 + return NULL; /* warning */
215 +static FD_t lzdReadOpen(int fdno, int fopen)
218 + unsigned char ff[8];
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;
227 + if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, lzfile->properties, sizeof(lzfile->properties))) {
229 + fclose(lzfile->g_InBuffer.File);
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)
237 + lzfile->state.Probs = (CProb *)malloc(LzmaGetNumProbs(&lzfile->state.Properties) * sizeof(CProb));
238 + if (lzfile->state.Probs == NULL) goto error;
240 + if (lzfile->state.Properties.DictionarySize == 0)
241 + lzfile->state.Dictionary = 0;
243 + lzfile->state.Dictionary = (unsigned char *)malloc(lzfile->state.Properties.DictionarySize);
244 + if (lzfile->state.Dictionary == NULL) {
245 + free(lzfile->state.Probs);
249 + lzfile->g_InBuffer.InCallback.Read = LzmaReadCompressed;
250 + LzmaDecoderInit(&lzfile->state);
252 + fd = fdNew("open (lzdOpen read)");
253 + if (fopen) fdPop(fd);
254 + fdPush(fd, lzdio, lzfile, -1);
255 + return fdLink(fd, "lzdOpen");
259 +static /*@null@*/ FD_t lzdOpen(const char * path, const char * mode)
260 + /*@globals fileSystem @*/
261 + /*@modifies fileSystem @*/
265 + if (mode[0] == 'w') {
266 + int fdno = open(path, O_WRONLY);
268 + if (fdno < 0) return NULL;
269 + return lzdWriteOpen(fdno, 1);
271 + int fdno = open(path, O_RDONLY);
273 + if (fdno < 0) return NULL;
274 + return lzdReadOpen(fdno, 1);
280 +static /*@null@*/ FD_t lzdFdopen(void * cookie, const char * fmode)
281 + /*@globals fileSystem, internalState @*/
282 + /*@modifies fileSystem, internalState @*/
284 + FD_t fd = c2f(cookie);
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);
294 + return lzdReadOpen(fdno, 0);
300 +static int lzdFlush(FD_t fd)
301 + /*@globals fileSystem @*/
302 + /*@modifies fileSystem @*/
304 + LZFILE *lzfile = lzdFileno(fd);
306 + if (lzfile == NULL || lzfile->g_InBuffer.File == NULL) return -2;
307 + return fflush(lzfile->g_InBuffer.File);
311 +/* =============================================================== */
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 @*/
318 + FD_t fd = c2f(cookie);
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)
328 + res = LzmaDecode(&lzfile->state, &lzfile->g_InBuffer.InCallback, buf, count, &rc);
332 + fd->errcookie = "Lzma: decoding error";
333 + } else if (rc >= 0) {
334 + fdstat_exit(fd, FDSTAT_READ, rc);
336 + if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
345 +static ssize_t lzdWrite(void * cookie, const char * buf, size_t count)
346 + /*@globals fileSystem, internalState @*/
347 + /*@modifies fileSystem, internalState @*/
349 + FD_t fd = c2f(cookie);
353 + if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
355 + if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
357 + lzfile = lzdFileno(fd);
358 + fdstat_enter(fd, FDSTAT_WRITE);
359 + rc = fwrite((void *)buf, 1, count, lzfile->g_InBuffer.File);
361 + fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
362 + } else if (rc > 0) {
363 + fdstat_exit(fd, FDSTAT_WRITE, rc);
369 +static inline int lzdSeek(void * cookie, /*@unused@*/ _libio_pos_t pos,
370 + /*@unused@*/ int whence)
373 + FD_t fd = c2f(cookie);
379 +static int lzdClose( /*@only@*/ void * cookie)
380 + /*@globals fileSystem, internalState @*/
381 + /*@modifies fileSystem, internalState @*/
383 + FD_t fd = c2f(cookie);
387 + lzfile = lzdFileno(fd);
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);
399 + /*@=noeffectuncon@*/
400 + rc = 0; /* XXX FIXME */
402 + /* XXX TODO: preserve fd if errors */
406 + fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
407 + } else if (rc >= 0) {
408 + fdstat_exit(fd, FDSTAT_CLOSE, rc);
412 +DBGIO(fd, (stderr, "==>\tlzdClose(%p) rc %lx %s\n", cookie, (unsigned long)rc, fdbg(fd)));
414 + if (_rpmio_debug || rpmIsDebug()) fdstat_print(fd, "LZDIO", stderr);
417 + fd = fdFree(fd, "open (lzdClose)");
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
428 +FDIO_t lzdio = /*@-compmempass@*/ &lzdio_s /*@=compmempass@*/ ;
430 /* =============================================================== */
432 static const char * getFdErrstr (FD_t fd)
433 @@ -2388,7 +2712,9 @@
434 errstr = fd->errcookie;
436 #endif /* HAVE_BZLIB_H */
438 + if (fdGetIo(fd) == lzdio) {
439 + errstr = fd->errcookie;
442 errstr = (fd->syserrno ? strerror(fd->syserrno) : "");
444 @@ -2683,6 +3009,9 @@
445 fd = bzdFdopen(fd, zstdio);
448 + } else if (!strcmp(end, "lzdio")) {
450 + fd = lzdFdopen(fd, zstdio);
451 } else if (!strcmp(end, "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 */
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 */
462 /* XXX need to check ufdio/gzdio/bzdio/fdio errors correctly. */
463 ec = (fdFileno(fd) < 0 ? -1 : 0);
464 diff -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
471 +/*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
475 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
478 diff -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
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),
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)
498 { "uncompress", RPMIOBITS_UNCOMPRESS },
499 { "binary", RPMIOBITS_BINARY },
500 { "dump", RPMIOBITS_DUMP },
501 { "xml", RPMIOBITS_XML },
502 + { "lzdio", RPMIOBITS_LZDIO },
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");
513 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */