]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Bring filelist and diskusage in sync for rpm parsers
authorMichael Schroeder <mls@suse.de>
Wed, 22 Feb 2017 10:34:56 +0000 (11:34 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 22 Feb 2017 10:34:56 +0000 (11:34 +0100)
ext/repo_rpmdb.c
ext/repo_rpmmd.c
ext/repo_susetags.c

index fe05becebe23724c97534d5c015dab1384e969a6..d99c37f02b6948ef7491664c4ed669189bad7454 100644 (file)
@@ -624,6 +624,24 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf,
   return olddeps;
 }
 
+static Id
+repodata_str2dir_rooted(Repodata *data, char *str, int create)
+{
+  char buf[256], *bp;
+  int l = strlen(str);
+  Id id;
+
+  if (l + 2 <= sizeof(buf))
+    bp = buf;
+  else
+    bp = solv_malloc(l + 2);
+  bp[0] = '/';
+  strcpy(bp + 1, str);
+  id = repodata_str2dir(data, bp, create);
+  if (bp != buf)
+    solv_free(bp);
+  return id;
+}
 
 static void
 adddudata(Repodata *data, Id handle, RpmHead *rpmhead, char **dn, unsigned int *di, int fc, int dc)
@@ -765,15 +783,16 @@ adddudata(Repodata *data, Id handle, RpmHead *rpmhead, char **dn, unsigned int *
     {
       if (!fn[i])
        continue;
-      did = repodata_str2dir(data, dn[i], 1);
-      if (!did)
+      if (dn[i][0] != '/')
        {
           Solvable *s = data->repo->pool->solvables + handle;
           if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
            did = repodata_str2dir(data, "/usr/src", 1);
          else
-           continue;   /* work around rpm bug */
+           did = repodata_str2dir_rooted(data, dn[i], 1);
        }
+      else
+        did = repodata_str2dir(data, dn[i], 1);
       repodata_add_dirnumnum(data, handle, SOLVABLE_DISKUSAGE, did, fkb[i], fn[i]);
     }
   solv_free(fn);
@@ -803,7 +822,7 @@ addfilelist(Repodata *data, Id handle, RpmHead *rpmhead, int flags)
   unsigned int *di;
   int bnc, dnc, dic;
   int i;
-  Id lastdid = 0;
+  Id did;
   unsigned int lastdii = -1;
   int lastfiltered = 0;
 
@@ -833,17 +852,16 @@ addfilelist(Repodata *data, Id handle, RpmHead *rpmhead, int flags)
 
   adddudata(data, handle, rpmhead, dn, di, bnc, dnc);
 
+  did = -1;
   for (i = 0; i < bnc; i++)
     {
-      Id did;
       char *b = bn[i];
 
-      if (lastdid && di[i] == lastdii)
-       did = lastdid;
-      else
+      if (did < 0 || di[i] != lastdii)
        {
          if (di[i] >= dnc)
            continue;   /* corrupt entry */
+         did = 0;
          lastdii = di[i];
          if ((flags & RPM_ADD_FILTERED_FILELIST) != 0)
            {
@@ -851,18 +869,17 @@ addfilelist(Repodata *data, Id handle, RpmHead *rpmhead, int flags)
              if (lastfiltered == 1)
                continue;
            }
-         did = repodata_str2dir(data, dn[lastdii], 1);
-         if (!did)
-           did = repodata_str2dir(data, "/", 1);
-         lastdid = did;
+         if (dn[lastdii][0] != '/')
+           did = repodata_str2dir_rooted(data, dn[lastdii], 1);
+         else
+           did = repodata_str2dir(data, dn[lastdii], 1);
        }
-      if (b && *b == '/')      /* work around rpm bug */
+      if (!b)
+       continue;
+      if (*b == '/')   /* work around rpm bug */
        b++;
-      if (lastfiltered)
-       {
-         if (lastfiltered != 2 || strcmp(b, "sendmail"))
-           continue;
-       }
+      if (lastfiltered && (lastfiltered != 2 || strcmp(b, "sendmail")))
+        continue;
       repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, b);
     }
   solv_free(bn);
index 8854bcac1c5086eacdedf161e5cf1d0062a63565..ff41906e4cd79d1ad2daf290cb560c42e1a92b64 100644 (file)
@@ -1021,15 +1021,20 @@ startElement(void *userData, const char *name, const char **atts)
          }
        if (*str != '/')
          {
-           int l = strlen(str) + 2;
-           if (l > pd->acontent)
+           if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
+             str = "/usr/src";
+           else
              {
-               pd->content = solv_realloc(pd->content, l + 256);
-               pd->acontent = l + 256;
-             }
-           *pd->content = '/';
-           strcpy(pd->content + 1, str);
-           str = pd->content;
+               int l = strlen(str) + 2;
+               if (l > pd->acontent)
+                 {
+                   pd->acontent = l + 256;
+                   pd->content = solv_realloc(pd->content, pd->acontent);
+                 }
+               pd->content[0] = '/';
+               memcpy(pd->content + 1, str, l - 1);
+               str = pd->content;
+           }
          }
         dirid = repodata_str2dir(pd->data, str, 1);
         if ((str = find_attr("size", atts)) != 0)
@@ -1161,10 +1166,6 @@ endElement(void *userData, const char *name)
         break;
       }
     case STATE_FILE:
-#if 0
-      id = pool_str2id(pool, pd->content, 1);
-      s->provides = repo_addid_dep(repo, s->provides, id, SOLVABLE_FILEMARKER);
-#endif
       if ((p = strrchr(pd->content, '/')) != 0)
        {
          *p++ = 0;
@@ -1174,25 +1175,29 @@ endElement(void *userData, const char *name)
            }
          else
            {
-             int l;
-             id = repodata_str2dir(pd->data, pd->content, 1);
-             l = strlen(pd->content) + 1;
-             if (l > pd->lastdirstrl)
+             int l = p - pd->content;
+             if (l + 1 > pd->lastdirstrl)      /* + 1 for the possible leading / we need to insert */
                {
                  pd->lastdirstrl = l + 128;
                  pd->lastdirstr = solv_realloc(pd->lastdirstr, pd->lastdirstrl);
                }
-             strcpy(pd->lastdirstr, pd->content);
+             if (pd->content[0] != '/')
+               {
+                 pd->lastdirstr[0] = '/';
+                 memcpy(pd->lastdirstr + 1, pd->content, l);
+                 id = repodata_str2dir(pd->data, pd->lastdirstr, 1);
+               }
+             else
+               id = repodata_str2dir(pd->data, pd->content, 1);
              pd->lastdir = id;
+             memcpy(pd->lastdirstr, pd->content, l);
            }
        }
       else
        {
          p = pd->content;
-         id = 0;
+         id = repodata_str2dir(pd->data, "/", 1);
        }
-      if (!id)
-       id = repodata_str2dir(pd->data, "/", 1);
       repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, id, p);
       break;
     case STATE_SUMMARY:
index 83967e0be6c63a50ff7b373e8e3c91b7ffb75ea0..448b06c04763c12bd48c770ef2c6a3d7ef14d2ed 100644 (file)
@@ -1065,27 +1065,22 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
 
          case CTAG('=', 'F', 'l', 's'):
            {
-             char *p = strrchr(line + 6, '/');
+             char *p, *file = line + 6;
              Id did;
-             /* strip trailing slash */
-             if (p && p != line + 6 && !p[1])
+
+             if (*file != '/')
+               *--file = '/';          /* hack: we know there is room */
+             p  = strrchr(file, '/');
+             /* strip trailing slashes */
+             while (p != file && !p[1])
                {
                  *p = 0;
-                 p = strrchr(line + 6, '/');
-               }
-             if (p)
-               {
-                 *p++ = 0;
-                 did = repodata_str2dir(data, line + 6, 1);
-               }
-             else
-               {
-                 p = line + 6;
-                 did = 0;
+                 p = strrchr(file, '/');
                }
-             if (!did)
-               did = repodata_str2dir(data, "/", 1);
+             *p++ = 0;
+             did = repodata_str2dir(data, *file ? file : "/", 1);
              repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, p);
+             line[5] = ' ';
              break;
            }
          case CTAG('=', 'H', 'd', 'r'):