- add dir reading code to solv reader
authorMichael Schroeder <mls@suse.de>
Tue, 15 Jan 2008 15:37:29 +0000 (15:37 +0000)
committerMichael Schroeder <mls@suse.de>
Tue, 15 Jan 2008 15:37:29 +0000 (15:37 +0000)
- change DU skeleton to use new layout
- add new type TYPE_DIR

src/pool.c
src/pool.h
src/pooltypes.h
src/repo.c
src/repo.h
src/repo_solv.c

index c2eab07..aff39bb 100644 (file)
@@ -938,39 +938,43 @@ pool_fill_DU(Pool *pool, struct mountpoint *mps, int nmps)
     {
       for_all_repodatas_containing_DU
        {
-         dirmap = xcalloc2(data->ndirs, sizeof(Id));
-         dirnum = 0;
-         for (;;)
+         /* create map from dir to mptree */
+         dirmap = xcalloc2(pool->ndirs, sizeof(Id));
+         mp = 0;
+         for (dn = 2, dirs = pool->dirs + dn; dn < pool->ndirs; dn++)
            {
-             parent = readid();
-             mp = parent ? dirmap[parent] : 0;
-             while (id = readid())
+             id = *dirs++;
+             if (id <= 0)
                {
-                 if (mp < 0)
-                   {
-                     /* unconnected */
-                     dirmap[dirnum++] = mp;
-                     continue;
-                   }
-                 if (!mptree[mp].child)
-                   {
-                     dirmap[dirnum++] = -mp;
-                     continue;
-                   }
-                 comp = id2str(pool, id);
-                 compl = strlen(comp);
-                 for (i = mptree[mp].child; i; i = mptree[i].sibling)
-                   if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
-                     break;
-                 dirmap[dirnum++] = i ? i : -mp;
+                 mp = dirmap[-id];
+                 continue;
                }
+             if (mp < 0)
+               {
+                 /* unconnected */
+                 dirmap[dn] = mp;
+                 continue;
+               }
+             if (!mptree[mp].child)
+               {
+                 dirmap[dn] = -mp;
+                 continue;
+               }
+             comp = id2str(pool, id);
+             compl = strlen(comp);
+             for (i = mptree[mp].child; i; i = mptree[i].sibling)
+               if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
+                 break;
+             dirmap[dn] = i ? i : -mp;
            }
-         for (i = 0; i < dirnum; i++)
+         /* change dirmap to point to mountpoint instead of mptree */
+         for (dn = 0; dn < pool->ndirs; dn++)
            {
              mp = dirmap[i];
              dirmap[i] = mptree[mp > 0 ? mp : -mp].mountpoint;
            }
-         cbdata.nmap = dirnum;
+
+         cbdata.nmap = pool->ndirs;
          cbdata.dirmap = dirmap;
 
          md.callback = pool_fill_DU_add_cb;
index a4f42c1..e62a9ff 100644 (file)
@@ -151,9 +151,11 @@ struct _Pool {
 #define TYPE_COUNTED           12
 
 #define TYPE_IDVALUEARRAY      13
-#define TYPE_IDVALUEVALUEARRAY 14
 
-#define TYPE_ATTR_TYPE_MAX     TYPE_IDVALUEVALUEARRAY
+#define TYPE_DIR               14
+#define TYPE_DIRVALUEVALUEARRAY        15
+
+#define TYPE_ATTR_TYPE_MAX     TYPE_DIRVALUEVALUEARRAY
 
 //-----------------------------------------------
 
index b64bbbc..0622a31 100644 (file)
@@ -18,6 +18,8 @@
 #define SOLV_VERSION_1 1
 #define SOLV_VERSION_2 2
 #define SOLV_VERSION_3 3
+#define SOLV_VERSION_4 4
+
 #define SOLV_FLAG_PACKEDSIZES 1
 #define SOLV_FLAG_VERTICAL    2
 #define SOLV_FLAG_PREFIX_POOL 4
index a18ae6c..bc8546d 100644 (file)
@@ -482,13 +482,14 @@ data_skip(unsigned char *dp, int type)
     case TYPE_VOID:
       return dp;
     case TYPE_ID:
+    case TYPE_DIR:
       while ((*dp & 0x80) != 0)
        dp++;
       return dp;
     case TYPE_IDARRAY:
     case TYPE_REL_IDARRAY:
     case TYPE_IDVALUEARRAY:
-    case TYPE_IDVALUEVALUEARRAY:
+    case TYPE_DIRVALUEVALUEARRAY:
       while ((*dp & 0xc0) != 0)
        dp++;
       return dp;
@@ -583,7 +584,7 @@ get_data(Repodata *data, Repokey *key, unsigned char **dpp)
        case TYPE_IDARRAY:
        case TYPE_REL_IDARRAY:
        case TYPE_IDVALUEARRAY:
-       case TYPE_IDVALUEVALUEARRAY:
+       case TYPE_DIRVALUEVALUEARRAY:
          for (i = 0; i < plen; i++)
            if ((dp[i] & 0xc0) == 0)
              return dp;
index 5fffec7..980eb0d 100644 (file)
@@ -64,9 +64,9 @@ typedef struct _Repodata {
   Id *incoreoffset;            /* offset for all entries (ent2attr) */
 
   Id verticaloffset;           /* file offset of verticals */
-  char *strbuf;                        /* just for testing */
-  int strbuflen;               /* just for testing */
 
+  Id *dirs;                    /* directory list */
+  int ndirs;                   /* its size */
 
   /* The attribute store itself.  */
   Attrstore *s;
index e09946b..a341d34 100644 (file)
@@ -255,7 +255,10 @@ skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
       case TYPE_VOID:
        break;
       case TYPE_ID:
-       read_id(data, numid + numrel);   /* just check Id */
+       read_id(data, numid + numrel);          /* just check Id */
+       break;
+      case TYPE_DIR:
+       read_id(data, numid + data->ndirs);     /* just check Id */
        break;
       case TYPE_U32:
        read_u32(data);
@@ -267,7 +270,7 @@ skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
        break;
       case TYPE_IDARRAY:
       case TYPE_IDVALUEARRAY:
-      case TYPE_IDVALUEVALUEARRAY:
+      case TYPE_DIRVALUEVALUEARRAY:
       case TYPE_REL_IDARRAY:
       case TYPE_ATTR_INTLIST:
        while ((read_u8(data) & 0xc0) != 0)
@@ -478,7 +481,7 @@ repo_add_solv(Repo *repo, FILE *fp)
 {
   Pool *pool = repo->pool;
   int i, l;
-  unsigned int numid, numrel, numsolv;
+  unsigned int numid, numrel, numdir, numsolv;
   unsigned int numkeys, numschemata, numinfo;
 #if 0
   Attrstore *embedded_store = 0;
@@ -525,6 +528,7 @@ repo_add_solv(Repo *repo, FILE *fp)
       case SOLV_VERSION_1:
       case SOLV_VERSION_2:
       case SOLV_VERSION_3:
+      case SOLV_VERSION_4:
         break;
       default:
         pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
@@ -535,14 +539,22 @@ repo_add_solv(Repo *repo, FILE *fp)
 
   numid = read_u32(&data);
   numrel = read_u32(&data);
+  if (solvversion >= SOLV_VERSION_4)
+    numdir = read_u32(&data);
+  else
+    numdir = 0;
   numsolv = read_u32(&data);
   numkeys = read_u32(&data);
   numschemata = read_u32(&data);
   numinfo = read_u32(&data);
   solvflags = read_u32(&data);
 
-  if (solvversion < SOLV_VERSION_3
-      && numinfo)
+  if (numdir && numdir < 2)
+    {
+      pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
+      return SOLV_ERROR_CORRUPT;
+    }
+  if (numinfo && solvversion < SOLV_VERSION_3)
     {
       pool_debug(pool, SAT_ERROR, "unsupported SOLV format (has info)\n");
       return SOLV_ERROR_UNSUPPORTED;
@@ -768,7 +780,25 @@ repo_add_solv(Repo *repo, FILE *fp)
     }
 
 
-  /*******  Part 3: Keys  ***********************************************/
+  /*******  Part 3: Dirs  ***********************************************/
+  if (numdir)
+    {
+      data.dirs = sat_calloc(numdir, sizeof(Id));
+      data.ndirs = numdir;
+      /* dir 0: no directory
+       * dir 1: /
+       */
+      for (i = 2; i < numdir; i++)
+       {
+         id = read_id(&data, i + numid);
+         if (i > numid)
+           data.dirs[i] = -(id - numid);
+         else
+           data.dirs[i] = idmap[id];
+       }
+    }
+
+  /*******  Part 4: Keys  ***********************************************/
 
   keys = sat_calloc(numkeys, sizeof(*keys));
   /* keys start at 1 */
@@ -821,7 +851,7 @@ repo_add_solv(Repo *repo, FILE *fp)
   data.keys = keys;
   data.nkeys = numkeys;
 
-  /*******  Part 4: Schemata ********************************************/
+  /*******  Part 5: Schemata ********************************************/
   
   id = read_id(&data, 0);
   schemadata = sat_calloc(id, sizeof(Id));
@@ -837,7 +867,7 @@ repo_add_solv(Repo *repo, FILE *fp)
   data.nschemata = numschemata;
   data.schemadata = schemadata;
 
-  /*******  Part 5: Info  ***********************************************/
+  /*******  Part 6: Info  ***********************************************/
   for (i = 0; i < numinfo; i++)
     {
       /* for now we're just interested in data that starts with
@@ -854,7 +884,7 @@ repo_add_solv(Repo *repo, FILE *fp)
        skip_schema(&data, keyp, keys, numid, numrel);
     }
 
-  /*******  Part 6: packed sizes (optional)  ****************************/
+  /*******  Part 7: packed sizes (optional)  ****************************/
   char *exists = 0;
   if ((solvflags & SOLV_FLAG_PACKEDSIZES) != 0)
     {
@@ -863,7 +893,7 @@ repo_add_solv(Repo *repo, FILE *fp)
        exists[i] = read_id(&data, 0) != 0;
     }
 
-  /*******  Part 7: item data *******************************************/
+  /*******  Part 8: item data *******************************************/
 
   /* calculate idarray size */
   size_idarray = 0;
@@ -1089,6 +1119,8 @@ repo_add_solv(Repo *repo, FILE *fp)
     }
   else
     {
+      /* discard data */
+      sat_free(data.dirs);
       sat_free(schemata);
       sat_free(schemadata);
       sat_free(keys);