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 { "rpmlib(FileDigestParameterized)", "4.4.6-1",
40 (RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
41 N_("file digests can be other than MD5.") },
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 rpmio.h rpmurl.h rpmmacro.h rpmlog.h rpmmessages.h rpmerr.h rpmpgp.h \
70 rpmsq.h rpmsw.h ugid.h
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
75 BEECRYPTLOBJS = $(shell test X"@WITH_BEECRYPT_SUBDIR@" != X && cat $(top_builddir)/@WITH_BEECTYPT_SUBDIR@/listobjs)
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 \
80 rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c strtolocale.c \
81 - stubs.c url.c ugid.c
82 + stubs.c url.c ugid.c \
84 librpmio_la_LDFLAGS = -no-undefined -release $(LT_CURRENT).$(LT_REVISION) $(LDFLAGS) \
87 diff -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
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)
96 #define UFDONLY(fd) /* assert(fdGetIo(fd) == ufdio) */
99 } else if (fps->io == bzdio) {
100 sprintf(be, "BZD %p fdno %d", fps->fp, fps->fdno);
102 + } else if (fps->io == lzdio) {
103 + sprintf(be, "LZD %p fdno %d", fps->fp, fps->fdno);
104 } else if (fps->io == fpio) {
106 sprintf(be, "%s %p(%d) fdno %d",
107 @@ -2370,6 +2373,327 @@
109 #endif /* HAVE_BZLIB_H */
111 +#include "LzmaDecode.h"
113 +#define kInBufferSize (1 << 15)
114 +typedef struct _CBuffer
116 + ILzmaInCallback InCallback;
118 + unsigned char Buffer[kInBufferSize];
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];
130 +static size_t MyReadFile(FILE *file, void *data, size_t size)
132 + if (size == 0) return 0;
133 + return fread(data, 1, size, file);
136 +static int MyReadFileAndCheck(FILE *file, void *data, size_t size)
138 + return (MyReadFile(file, data, size) == size);
141 +static int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
143 + CBuffer *b = (CBuffer *)object;
144 + *buffer = b->Buffer;
145 + *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);
146 + return LZMA_RESULT_OK;
149 +static inline /*@dependent@*/ void * lzdFileno(FD_t fd)
156 + for (i = fd->nfps; i >= 0; i--) {
158 + FDSTACK_t * fps = &fd->fps[i];
160 + if (fps->io != lzdio)
169 +static FD_t lzdWriteOpen(int fdno, int fopen)
174 + if (fdno < 0) return NULL;
190 + lzfile = calloc(1, sizeof(*lzfile));
191 + if (lzfile == NULL) return NULL;
192 + lzfile->g_InBuffer.File = fdopen(p[1], "wb");
194 + if (lzfile->g_InBuffer.File == NULL) {
199 + fd = fdNew("open (lzdOpen write)");
200 + if (fopen) fdPop(fd);
201 + fdPush(fd, lzdio, lzfile, -1);
202 + return fdLink(fd, "lzdOpen");
209 + for (i = 3; i < 1024; i++) close(i);
210 + if (execl("/usr/bin/lzma", "lzma", "e", "-si", "-so", NULL)) {
214 + return NULL; /* warning */
217 +static FD_t lzdReadOpen(int fdno, int fopen)
220 + unsigned char ff[8];
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;
229 + if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, lzfile->properties, sizeof(lzfile->properties))) {
231 + fclose(lzfile->g_InBuffer.File);
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)
239 + lzfile->state.Probs = (CProb *)malloc(LzmaGetNumProbs(&lzfile->state.Properties) * sizeof(CProb));
240 + if (lzfile->state.Probs == NULL) goto error;
242 + if (lzfile->state.Properties.DictionarySize == 0)
243 + lzfile->state.Dictionary = 0;
245 + lzfile->state.Dictionary = (unsigned char *)malloc(lzfile->state.Properties.DictionarySize);
246 + if (lzfile->state.Dictionary == NULL) {
247 + free(lzfile->state.Probs);
251 + lzfile->g_InBuffer.InCallback.Read = LzmaReadCompressed;
252 + LzmaDecoderInit(&lzfile->state);
254 + fd = fdNew("open (lzdOpen read)");
255 + if (fopen) fdPop(fd);
256 + fdPush(fd, lzdio, lzfile, -1);
257 + return fdLink(fd, "lzdOpen");
261 +static /*@null@*/ FD_t lzdOpen(const char * path, const char * mode)
262 + /*@globals fileSystem @*/
263 + /*@modifies fileSystem @*/
267 + if (mode[0] == 'w') {
268 + int fdno = open(path, O_WRONLY);
270 + if (fdno < 0) return NULL;
271 + return lzdWriteOpen(fdno, 1);
273 + int fdno = open(path, O_RDONLY);
275 + if (fdno < 0) return NULL;
276 + return lzdReadOpen(fdno, 1);
282 +static /*@null@*/ FD_t lzdFdopen(void * cookie, const char * fmode)
283 + /*@globals fileSystem, internalState @*/
284 + /*@modifies fileSystem, internalState @*/
286 + FD_t fd = c2f(cookie);
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);
296 + return lzdReadOpen(fdno, 0);
302 +static int lzdFlush(FD_t fd)
303 + /*@globals fileSystem @*/
304 + /*@modifies fileSystem @*/
306 + LZFILE *lzfile = lzdFileno(fd);
308 + if (lzfile == NULL || lzfile->g_InBuffer.File == NULL) return -2;
309 + return fflush(lzfile->g_InBuffer.File);
313 +/* =============================================================== */
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 @*/
320 + FD_t fd = c2f(cookie);
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)
330 + res = LzmaDecode(&lzfile->state, &lzfile->g_InBuffer.InCallback, buf, count, &rc);
334 + fd->errcookie = "Lzma: decoding error";
335 + } else if (rc >= 0) {
336 + fdstat_exit(fd, FDSTAT_READ, rc);
338 + if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
347 +static ssize_t lzdWrite(void * cookie, const char * buf, size_t count)
348 + /*@globals fileSystem, internalState @*/
349 + /*@modifies fileSystem, internalState @*/
351 + FD_t fd = c2f(cookie);
355 + if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
357 + if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
359 + lzfile = lzdFileno(fd);
360 + fdstat_enter(fd, FDSTAT_WRITE);
361 + rc = fwrite((void *)buf, 1, count, lzfile->g_InBuffer.File);
363 + fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
364 + } else if (rc > 0) {
365 + fdstat_exit(fd, FDSTAT_WRITE, rc);
371 +static inline int lzdSeek(void * cookie, /*@unused@*/ _libio_pos_t pos,
372 + /*@unused@*/ int whence)
375 + FD_t fd = c2f(cookie);
381 +static int lzdClose( /*@only@*/ void * cookie)
382 + /*@globals fileSystem, internalState @*/
383 + /*@modifies fileSystem, internalState @*/
385 + FD_t fd = c2f(cookie);
389 + lzfile = lzdFileno(fd);
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);
401 + /*@=noeffectuncon@*/
402 + rc = 0; /* XXX FIXME */
404 + /* XXX TODO: preserve fd if errors */
408 + fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
409 + } else if (rc >= 0) {
410 + fdstat_exit(fd, FDSTAT_CLOSE, rc);
414 +DBGIO(fd, (stderr, "==>\tlzdClose(%p) rc %lx %s\n", cookie, (unsigned long)rc, fdbg(fd)));
416 + if (_rpmio_debug || rpmIsDebug()) fdstat_print(fd, "LZDIO", stderr);
419 + fd = fdFree(fd, "open (lzdClose)");
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
430 +FDIO_t lzdio = /*@-compmempass@*/ &lzdio_s /*@=compmempass@*/ ;
432 /* =============================================================== */
434 static const char * getFdErrstr (FD_t fd)
435 @@ -2388,7 +2712,9 @@
436 errstr = fd->errcookie;
438 #endif /* HAVE_BZLIB_H */
440 + if (fdGetIo(fd) == lzdio) {
441 + errstr = fd->errcookie;
444 errstr = (fd->syserrno ? strerror(fd->syserrno) : "");
446 @@ -2683,6 +3009,9 @@
447 fd = bzdFdopen(fd, zstdio);
450 + } else if (!strcmp(end, "lzdio")) {
452 + fd = lzdFdopen(fd, zstdio);
453 } else if (!strcmp(end, "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 */
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 */
464 /* XXX need to check ufdio/gzdio/bzdio/fdio errors correctly. */
465 ec = (fdFileno(fd) < 0 ? -1 : 0);
466 diff -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
473 +/*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
477 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
480 diff -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
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),
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)
500 { "uncompress", RPMIOBITS_UNCOMPRESS },
501 { "binary", RPMIOBITS_BINARY },
502 { "dump", RPMIOBITS_DUMP },
503 { "xml", RPMIOBITS_XML },
504 + { "lzdio", RPMIOBITS_LZDIO },
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");
515 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */