RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [EMAIL PROTECTED]
  Module: rpm                              Date:   31-May-2008 17:10:22
  Branch: HEAD                             Handle: 2008053115102101

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               lzdio.c rpmio.c

  Log:
    - jbj: make sure the open path is set when using [bgl]zdOpen vector too.
    - jbj: lzdio: rework the layering to be more similar to gzdio/bzdio.
    - jbj: rpmrepo: fix: --lzma segfault, lzdFdopen was not saving path.

  Summary:
    Revision    Changes     Path
    1.2384      +3  -0      rpm/CHANGES
    1.4         +78 -82     rpm/rpmio/lzdio.c
    1.132       +8  -2      rpm/rpmio/rpmio.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2383 -r1.2384 CHANGES
  --- rpm/CHANGES       30 May 2008 21:25:31 -0000      1.2383
  +++ rpm/CHANGES       31 May 2008 15:10:21 -0000      1.2384
  @@ -1,5 +1,8 @@
   
   5.1.0 -> 5.2a0:
  +    - jbj: make sure the open path is set when using [bgl]zdOpen vector too.
  +    - jbj: lzdio: rework the layering to be more similar to gzdio/bzdio.
  +    - jbj: rpmrepo: fix: --lzma segfault, lzdFdopen was not saving path.
       - jbj: permit upgrade erasure of old -debuginfo iff all other packages
        built from same *.src.rpm are not present. Note that this patch
        assumes that -debuginfo will be added after all other packages
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/lzdio.c
  ============================================================================
  $ cvs diff -u -r1.3 -r1.4 lzdio.c
  --- rpm/rpmio/lzdio.c 5 May 2008 22:31:15 -0000       1.3
  +++ rpm/rpmio/lzdio.c 31 May 2008 15:10:22 -0000      1.4
  @@ -71,10 +71,10 @@
   
       FDSANE(fd);
       for (i = fd->nfps; i >= 0; i--) {
  -         FDSTACK_t * fps = &fd->fps[i];
  -         if (fps->io != lzdio)
  -             continue;
  -         rc = fps->fp;
  +     FDSTACK_t * fps = &fd->fps[i];
  +     if (fps->io != lzdio)
  +         continue;
  +     rc = fps->fp;
        break;
       }
       
  @@ -82,7 +82,7 @@
   }
   
   /[EMAIL PROTECTED]@*/        /* XXX hide rpmGlobalMacroContext mods for now. 
*/
  -static FD_t lzdWriteOpen(int fdno, int fopen, const char * mode)
  +static LZFILE * lzdWriteOpen(int fdno, const char * fmode)
        /[EMAIL PROTECTED] fileSystem, internalState @*/
        /[EMAIL PROTECTED] fileSystem, internalState @*/
   {
  @@ -90,71 +90,62 @@
       int p[2];
       int xx;
       const char *lzma;
  -    char l[3];
  +    char l[3] = "-7";        /* XXX same as default */
       const char *level;
   
       /* revisit use of LZMA_Alone, when lzdRead supports new LZMA Utils */
       char *env[] = { "LZMA_OPT=--format=alone", NULL };
   
  -    if (isdigit(mode[1])) /* "w9" */
  -    {
  -        sprintf(l, "-%c", mode[1]);
  -        level = l;
  -    }
  -    else
  -        level = NULL;
  +    if (fmode != NULL && fmode[0] == 'w' && xisdigit(fmode[1])) /* "w9" */
  +     l[1] = fmode[1];
  +    level = l;
   
       if (fdno < 0) return NULL;
       if (pipe(p) < 0) {
  -        xx = close(fdno);
  -        return NULL;
  +     xx = close(fdno);
  +     return NULL;
       }
       pid = fork();
       if (pid < 0) {
  -        xx = close(fdno);
  -        return NULL;
  +     xx = close(fdno);
  +     return NULL;
       }
       if (pid) {
  -        FD_t fd;
  -        LZFILE * lzfile = xcalloc(1, sizeof(*lzfile));
  +     LZFILE * lzfile = xcalloc(1, sizeof(*lzfile));
   
  -        xx = close(fdno);
  -        xx = close(p[0]);
  -        lzfile->pid = pid;
  -        lzfile->g_InBuffer.File = fdopen(p[1], "wb");
  -        if (lzfile->g_InBuffer.File == NULL) {
  -            xx = close(p[1]);
  -            lzfile = _free(lzfile);
  -            return NULL;
  -        }
  -        fd = fdNew("open (lzdOpen write)");
  -        if (fopen) fdPop(fd);
  -        fdPush(fd, lzdio, lzfile, -1);
  -        return fdLink(fd, "lzdOpen");
  +     xx = close(fdno);
  +     xx = close(p[0]);
  +     lzfile->pid = pid;
  +     lzfile->g_InBuffer.File = fdopen(p[1], "wb");
  +     if (lzfile->g_InBuffer.File == NULL) {
  +         xx = close(p[1]);
  +         lzfile = _free(lzfile);
  +         return NULL;
  +     }
  +     return lzfile;
       } else {
  -        int i;
  -        /* lzma */
  -        xx = close(p[1]);
  -        xx = dup2(p[0], 0);
  -        xx = dup2(fdno, 1);
  -        for (i = 3; i < 1024; i++)
  +     int i;
  +     /* lzma */
  +     xx = close(p[1]);
  +     xx = dup2(p[0], 0);
  +     xx = dup2(fdno, 1);
  +     for (i = 3; i < 1024; i++)
            xx = close(i);
  -        lzma = rpmGetPath("%{?__lzma}%{!?__lzma:/usr/bin/lzma}", NULL);
  -        if (execle(lzma, "lzma", level, NULL, env))
  -            _exit(1);
  -        lzma = _free(lzma);
  +     lzma = rpmGetPath("%{?__lzma}%{!?__lzma:/usr/bin/lzma}", NULL);
  +     if (execle(lzma, "lzma", level, NULL, env))
  +         _exit(1);
  +     lzma = _free(lzma);
       }
       return NULL; /* warning */
   }
   /[EMAIL PROTECTED]@*/
   
  -static FD_t lzdReadOpen(int fdno, int fopen)
  +static LZFILE * lzdReadOpen(int fdno)
        /[EMAIL PROTECTED] fileSystem @*/
        /[EMAIL PROTECTED] fileSystem @*/
   {
  -    LZFILE *lzfile;
  +    LZFILE * lzfile;
       unsigned char ff[8];
  -    FD_t fd;
       size_t nb;
   
       if (fdno < 0) return NULL;
  @@ -164,32 +155,29 @@
       if (lzfile->g_InBuffer.File == NULL) goto error2;
   
       if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, lzfile->properties, 
sizeof(lzfile->properties)))
  -            goto error;
  +     goto error;
   
       memset(ff, 0, sizeof(ff));
       if (!MyReadFileAndCheck(lzfile->g_InBuffer.File, ff, 8)) goto error;
       if (LzmaDecodeProperties(&lzfile->state.Properties, lzfile->properties, 
LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
  -        goto error;
  +     goto error;
       nb = LzmaGetNumProbs(&lzfile->state.Properties) * 
sizeof(*lzfile->state.Probs);
       lzfile->state.Probs = xmalloc(nb);
       if (lzfile->state.Probs == NULL) goto error;
   
       if (lzfile->state.Properties.DictionarySize == 0)
  -        lzfile->state.Dictionary = 0;
  +     lzfile->state.Dictionary = 0;
       else {
  -        lzfile->state.Dictionary = 
xmalloc(lzfile->state.Properties.DictionarySize);
  -        if (lzfile->state.Dictionary == NULL) {
  -            lzfile->state.Probs = _free(lzfile->state.Probs);
  -            goto error;
  -        }
  +     lzfile->state.Dictionary = 
xmalloc(lzfile->state.Properties.DictionarySize);
  +     if (lzfile->state.Dictionary == NULL) {
  +         lzfile->state.Probs = _free(lzfile->state.Probs);
  +         goto error;
  +     }
       }
       lzfile->g_InBuffer.InCallback.Read = LzmaReadCompressed;
       LzmaDecoderInit(&lzfile->state);
   
  -    fd = fdNew("open (lzdOpen read)");
  -    if (fopen) fdPop(fd);
  -    fdPush(fd, lzdio, lzfile, -1);
  -    return fdLink(fd, "lzdOpen");
  +    return lzfile;
   
   error:
       (void) fclose(lzfile->g_InBuffer.File);
  @@ -199,23 +187,29 @@
   }
   
   /[EMAIL PROTECTED]@*/
  -static /[EMAIL PROTECTED]@*/ FD_t lzdOpen(const char * path, const char * 
mode)
  +static /[EMAIL PROTECTED]@*/ FD_t lzdOpen(const char * path, const char * 
fmode)
        /[EMAIL PROTECTED] fileSystem, internalState @*/
        /[EMAIL PROTECTED] fileSystem, internalState @*/
   {
  -    if (mode == NULL)
  -        return NULL;
  -    if (mode[0] == 'w') {
  -        int fdno = open(path, O_WRONLY);
  +    FD_t fd;
  +    mode_t mode = (fmode && fmode[0] == 'w' ? O_WRONLY : O_RDONLY);
  +    int fdno = open(path, mode);
  +    LZFILE * lzfile = (mode == O_WRONLY)
  +     ? lzdWriteOpen(fdno, fmode)
  +     : lzdReadOpen(fdno);
  +
  +    if (lzfile == NULL) {
  +     if (fdno >= 0) (void) close(fdno);
  +     return NULL;
  +    }
  +
  +    fd = fdNew("open (lzdOpen)");
  +    fdPop(fd); fdPush(fd, lzdio, lzfile, -1);
  +    fdSetOpen(fd, path, fdno, mode);
   
  -        if (fdno < 0) return NULL;
  -        return lzdWriteOpen(fdno, 1, mode);
  -    } else {
  -        int fdno = open(path, O_RDONLY);
  +DBGIO(fd, (stderr, "==>\tlzdOpen(\"%s\", \"%s\") fd %p %s\n", path, fmode, 
(fd ? fd : NULL), fdbg(fd)));
   
  -        if (fdno < 0) return NULL;
  -        return lzdReadOpen(fdno, 1);
  -    }
  +    return fdLink(fd, "lzdOpen");
   }
   /[EMAIL PROTECTED]@*/
   
  @@ -225,17 +219,17 @@
        /[EMAIL PROTECTED] fileSystem, internalState @*/
   {
       FD_t fd = c2f(cookie);
  -    int fdno;
  +    int fdno = fdFileno(fd);
  +    LZFILE * lzfile;
   
  -    if (fmode == NULL) return NULL;
  -    fdno = fdFileno(fd);
  +assert(fmode != NULL);
       fdSetFdno(fd, -1);               /* XXX skip the fdio close */
  -    if (fdno < 0) return NULL;
  -    if (fmode[0] == 'w') {
  -        return lzdWriteOpen(fdno, 0, fmode);
  -    } else {
  -        return lzdReadOpen(fdno, 0);
  -    }
  +    lzfile = (fmode[0] == 'w')
  +     ? lzdWriteOpen(fdno, fmode)
  +     : lzdReadOpen(fdno);
  +    if (lzfile == NULL) return NULL;
  +    fdPush(fd, lzdio, lzfile, fdno);
  +    return fdLink(fd, "lzdFdopen");
   }
   /[EMAIL PROTECTED]@*/
   
  @@ -262,7 +256,7 @@
   {
       FD_t fd = c2f(cookie);
       LZFILE *lzfile;
  -    ssize_t rc = 0;
  +    ssize_t rc = -1;
       size_t out;
       int res = 0;
   
  @@ -272,9 +266,10 @@
       if (lzfile->g_InBuffer.File) {
   /[EMAIL PROTECTED]@*/
        res = LzmaDecode(&lzfile->state, &lzfile->g_InBuffer.InCallback, 
(unsigned char *)buf, count, &out);
  -        rc = (ssize_t)out;
  +     rc = (ssize_t)out;
       }
   /[EMAIL PROTECTED]@*/
  +DBGIO(fd, (stderr, "==>\tlzdRead(%p,%p,%u) rc %lx %s\n", cookie, buf, 
(unsigned)count, (unsigned long)rc, fdbg(fd)));
       if (res) {
        if (lzfile)
            fd->errcookie = "Lzma: decoding error";
  @@ -305,6 +300,7 @@
       lzfile = lzdFileno(fd);
       fdstat_enter(fd, FDSTAT_WRITE);
       rc = fwrite((void *)buf, 1, count, lzfile->g_InBuffer.File);
  +DBGIO(fd, (stderr, "==>\tlzdWrite(%p,%p,%u) rc %lx %s\n", cookie, buf, 
(unsigned)count, (unsigned long)rc, fdbg(fd)));
       if (rc == -1) {
        fd->errcookie = strerror(ferror(lzfile->g_InBuffer.File));
       } else if (rc > 0) {
  @@ -339,8 +335,8 @@
       if (lzfile->pid)
        rc = (int) wait4(lzfile->pid, NULL, 0, NULL);
       else { /* reading */
  -        lzfile->state.Probs = _free(lzfile->state.Probs);
  -        lzfile->state.Dictionary = _free(lzfile->state.Dictionary);
  +     lzfile->state.Probs = _free(lzfile->state.Probs);
  +     lzfile->state.Dictionary = _free(lzfile->state.Dictionary);
       }
   /[EMAIL PROTECTED]@*/
       lzfile = _free(lzfile);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmio.c
  ============================================================================
  $ cvs diff -u -r1.131 -r1.132 rpmio.c
  --- rpm/rpmio/rpmio.c 31 May 2008 14:40:39 -0000      1.131
  +++ rpm/rpmio/rpmio.c 31 May 2008 15:10:22 -0000      1.132
  @@ -2340,10 +2340,13 @@
   {
       FD_t fd;
       gzFile gzfile;
  +    mode_t mode = (fmode && fmode[0] == 'w' ? O_WRONLY : O_RDONLY);
  +
       if ((gzfile = gzopen(path, fmode)) == NULL)
        return NULL;
       fd = fdNew("open (gzdOpen)");
       fdPop(fd); fdPush(fd, gzdio, gzfile, -1);
  +    fdSetOpen(fd, path, -1, mode);
   
   DBGIO(fd, (stderr, "==>\tgzdOpen(\"%s\", \"%s\") fd %p %s\n", path, fmode, 
(fd ? fd : NULL), fdbg(fd)));
       return fdLink(fd, "gzdOpen");
  @@ -2559,16 +2562,19 @@
   }
   
   /[EMAIL PROTECTED]@*/
  -static /[EMAIL PROTECTED]@*/ FD_t bzdOpen(const char * path, const char * 
mode)
  +static /[EMAIL PROTECTED]@*/ FD_t bzdOpen(const char * path, const char * 
fmode)
        /[EMAIL PROTECTED] fileSystem @*/
        /[EMAIL PROTECTED] fileSystem @*/
   {
       FD_t fd;
       BZFILE *bzfile;;
  -    if ((bzfile = BZ2_bzopen(path, mode)) == NULL)
  +    mode_t mode = (fmode && fmode[0] == 'w' ? O_WRONLY : O_RDONLY);
  +
  +    if ((bzfile = BZ2_bzopen(path, fmode)) == NULL)
        return NULL;
       fd = fdNew("open (bzdOpen)");
       fdPop(fd); fdPush(fd, bzdio, bzfile, -1);
  +    fdSetOpen(fd, path, -1, mode);
       return fdLink(fd, "bzdOpen");
   }
   /[EMAIL PROTECTED]@*/
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to