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

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   08-Dec-2009 18:46:41
  Branch: HEAD                             Handle: 2009120817464000

  Modified files:
    rpm                     CHANGES
    rpm/rpmdb               db3.c

  Log:
    - rpmdb: lazily create non-existent secondary indices.

  Summary:
    Revision    Changes     Path
    1.3186      +1  -0      rpm/CHANGES
    1.129       +18 -11     rpm/rpmdb/db3.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3185 -r1.3186 CHANGES
  --- rpm/CHANGES       8 Dec 2009 15:37:23 -0000       1.3185
  +++ rpm/CHANGES       8 Dec 2009 17:46:40 -0000       1.3186
  @@ -1,5 +1,6 @@
   
   5.2b1 -> 5.3a1
  +    - jbj: rpmdb: lazily create non-existent secondary indices.
       - jbj: rpmdb: consolidate primary key swabbing to network order.
       - jbj: rpmdb: re-open dbenv w DB_RUNRECOVER rather than remove/verify.
       - jbj: rpmdb: handle optional .A just like optional -V and -R patterns.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/db3.c
  ============================================================================
  $ cvs diff -u -r1.128 -r1.129 db3.c
  --- rpm/rpmdb/db3.c   8 Dec 2009 15:37:24 -0000       1.128
  +++ rpm/rpmdb/db3.c   8 Dec 2009 17:46:40 -0000       1.129
  @@ -1531,14 +1531,19 @@
       uint32_t i;
   
       /* XXX Don't index the header instance counter at record 0. */
  -    if (key->size == 4 && *(uint32_t *)key->data == 0)
  -     return rc;
  +    {        static uint32_t _zero = 0;
  +     if (key->size == 4 && !memcmp(key->data, &_zero, key->size))
  +         goto exit;
  +    }
   
   assert(dbi);
       rpmdb = dbi->dbi_rpmdb;
   assert(rpmdb);
  -    h = rpmdb->db_h;
  -assert(h);
  +    h = headerLink(rpmdb->db_h);
  +    if (h == NULL) {
  +     h = headerLoad(data->data);
  +     if (h == NULL) goto exit;
  +    }
   
       memset(_r, 0, sizeof(*_r));
   
  @@ -1553,7 +1558,7 @@
   #ifdef       NOTYET
       case RPMTAG_BASENAMES:
       case RPMTAG_FILEPATHS:
  -     /* Add the pesky trailing '/' to directories. */
  +     /* XXX Add the pesky trailing '/' to directories. */
        FMhe->tag = RPMTAG_FILEMODES;
        (void) headerGet(h, FMhe, 0);
        break;
  @@ -1719,6 +1724,7 @@
   #endif
       Fhe->p.ptr = _free(Fhe->p.ptr);
       he->p.ptr = _free(he->p.ptr);
  +    h = headerFree(h);
   
   DBIDEBUG(dbi, (stderr, "<-- %s(%p, %p, %p, %p) rc %d\n\tdbi %p(%s) rpmdb %p 
h %p %s\n", __FUNCTION__, db, key, data, _r, rc, dbi, tagName(dbi->dbi_rpmtag), 
rpmdb, h, _KEYDATA(key, data, _r)));
   
  @@ -1876,7 +1882,8 @@
       }
   
       oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
  -    oflags &= ~DB_TRUNCATE;  /* XXX this is dangerous */
  +    /* XXX permit DB_TRUNCATE iff a secondary index. */
  +    if (!dbi->dbi_index) oflags &= ~DB_TRUNCATE;
   
   #if 0        /* XXX rpmdb: illegal flag combination specified to DB->open */
       if ( dbi->dbi_mode & O_EXCL) oflags |= DB_EXCL;
  @@ -1896,9 +1903,8 @@
            oflags |= DB_CREATE;
            dbi->dbi_oeflags |= DB_CREATE;
        }
  -#ifdef       DANGEROUS
  -     if ( dbi->dbi_mode & O_TRUNC) oflags |= DB_TRUNCATE;
  -#endif
  +     /* XXX permit DB_TRUNCATE iff a secondary index. */
  +     if (dbi->dbi_index && (dbi->dbi_mode & O_TRUNC)) oflags |= DB_TRUNCATE;
       }
   
       /*
  @@ -2010,9 +2016,9 @@
       }
   
       /*
  -     * Set db type if creating.
  +     * Set db type if creating or truncating.
        */
  -    if (oflags & DB_CREATE)
  +    if (oflags & (DB_CREATE|DB_TRUNCATE))
        dbi_type = dbi->dbi_type;
   
       /*
  @@ -2348,6 +2354,7 @@
                        = db3Acallback;
            int _flags = (rpmdb->_dbi[0]->dbi_eflags & DB_INIT_TXN)
                        ? DB_AUTO_COMMIT : 0;
  +         if (oflags & (DB_CREATE|DB_TRUNCATE)) _flags |= DB_CREATE;
            xx = db3associate(rpmdb->_dbi[0], dbi, _callback, _flags);
        }
        if (dbi->dbi_seq_id) {
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to