Imported Upstream version 0.7.2
[platform/upstream/libsolv.git] / ext / repo_arch.c
index 0a9089e..698d506 100644 (file)
@@ -196,14 +196,14 @@ static int gettarhead(struct tarhead *th)
            char *data, *pp;
            if (length < 1 || length >= 1024 * 1024)
              return -1;
-           l = length;
-           data = pp = solv_malloc(l + 512);
-           for (; l > 0; l -= 512, pp += 512)
+           data = pp = solv_malloc(length + 512);
+           for (l = length; l > 0; l -= 512, pp += 512)
              if (readblock(th->fp, (unsigned char *)pp))
                {
                  solv_free(data);
                  return -1;
                }
+           data[length] = 0;
            type = 3;           /* extension */
            if (th->blk[156] == 'L')
              {
@@ -216,7 +216,6 @@ static int gettarhead(struct tarhead *th)
            while (length > 0)
              {
                int ll = 0;
-               int l;
                for (l = 0; l < length && pp[l] >= '0' && pp[l] <= '9'; l++)
                  ll = ll * 10 + (pp[l] - '0');
                if (l == length || pp[l] != ' ' || ll < 1 || ll > length || pp[ll - 1] != '\n')
@@ -256,7 +255,7 @@ static int gettarhead(struct tarhead *th)
              memcpy(prefix, th->blk + 345, 155);
              prefix[155] = 0;
              l = strlen(prefix);
-             if (prefix[l - 1] == '/')
+             if (l && prefix[l - 1] == '/')
                prefix[l - 1] = 0;
              th->path = solv_dupjoin(prefix, "/", path);
            }
@@ -295,19 +294,19 @@ adddep(Repo *repo, Offset olddeps, char *line)
   char *p;
   Id id;
 
-  while (*line == ' ' && *line == '\t')
+  while (*line == ' ' || *line == '\t')
     line++;
   p = line;
   while (*p && *p != ' ' && *p != '\t' && *p != '<' && *p != '=' && *p != '>')
     p++;
   id = pool_strn2id(pool, line, p - line, 1);
-  while (*p == ' ' && *p == '\t')
+  while (*p == ' ' || *p == '\t')
     p++;
   if (*p == '<' || *p == '=' || *p == '>')
     {
       int flags = 0;
       for (;; p++)
-       {  
+       {
          if (*p == '<')
            flags |= REL_LT;
          else if (*p == '=')
@@ -317,7 +316,7 @@ adddep(Repo *repo, Offset olddeps, char *line)
          else
            break;
        }
-      while (*p == ' ' && *p == '\t')
+      while (*p == ' ' || *p == '\t')
         p++;
       line = p;
       while (*p && *p != ' ' && *p != '\t')
@@ -339,23 +338,23 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
   Solvable *s;
   int l, fd;
   struct stat stb;
-  void *pkgidhandle = 0;
+  Chksum *pkgidchk = 0;
 
   data = repo_add_repodata(repo, flags);
-  if ((fd = open(fn, O_RDONLY, 0)) < 0)
+  if ((fd = open(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, fn) : fn, O_RDONLY, 0)) < 0)
     {
-      pool_debug(pool, SOLV_ERROR, "repo_add_arch_pkg: %s: %s\n", fn, strerror(errno));
+      pool_error(pool, -1, "%s: %s", fn, strerror(errno));
       return 0;
     }
   if (fstat(fd, &stb))
     {
-      pool_debug(pool, SOLV_ERROR, "repo_add_arch_pkg: %s: fstat failed\n", fn);
+      pool_error(pool, -1, "%s: fstat: %s", fn, strerror(errno));
       close(fd);
       return 0;
     }
   if (!(fp = solv_xfopen_fd(fn, fd, "r")))
     {
-      pool_debug(pool, SOLV_ERROR, "repo_add_arch_pkg: %s: fdopen failed\n", fn);
+      pool_error(pool, -1, "%s: fdopen failed", fn);
       close(fd);
       return 0;
     }
@@ -371,14 +370,14 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
       ignoreline = 0;
       s = pool_id2solvable(pool, repo_add_solvable(repo));
       if (flags & ARCH_ADD_WITH_PKGID)
-       pkgidhandle = solv_chksum_create(REPOKEY_TYPE_MD5);
+       pkgidchk = solv_chksum_create(REPOKEY_TYPE_MD5);
       while (getsentry(&th, line, sizeof(line)))
        {
          l = strlen(line);
          if (l == 0)
            continue;
-         if (pkgidhandle)
-           solv_chksum_add(pkgidhandle, line, l);
+         if (pkgidchk)
+           solv_chksum_add(pkgidchk, line, l);
          if (line[l - 1] != '\n')
            {
              ignoreline = 1;
@@ -412,11 +411,11 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
          else if (!strncmp(line, "arch = ", 7))
            s->arch = pool_str2id(pool, line + 7, 1);
          else if (!strncmp(line, "license = ", 10))
-           repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_LICENSE, line + 10);
+           repodata_add_poolstr_array(data, s - pool->solvables, SOLVABLE_LICENSE, line + 10);
          else if (!strncmp(line, "replaces = ", 11))
            s->obsoletes = adddep(repo, s->obsoletes, line + 11);
          else if (!strncmp(line, "group = ", 8))
-           repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_GROUP, line + 8);
+           repodata_add_poolstr_array(data, s - pool->solvables, SOLVABLE_GROUP, line + 8);
          else if (!strncmp(line, "depend = ", 9))
            s->requires = adddep(repo, s->requires, line + 9);
          else if (!strncmp(line, "optdepend = ", 12))
@@ -435,10 +434,17 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
     }
   freetarhead(&th);
   fclose(fp);
+  if (!s)
+    {
+      pool_error(pool, -1, "%s: not an arch package", fn);
+      if (pkgidchk)
+       solv_chksum_free(pkgidchk, 0);
+      return 0;
+    }
   if (s && !s->name)
     {
-      repo_free_solvable(repo, s - pool->solvables, 1);
-      s = 0;
+      pool_error(pool, -1, "%s: package has no name", fn);
+      s = solvable_free(s, 1);
     }
   if (s)
     {
@@ -447,18 +453,20 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags)
       if (!s->evr)
        s->evr = ID_EMPTY;
       s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
-      repodata_set_location(data, s - pool->solvables, 0, 0, fn);
-      repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
-      if (pkgidhandle)
+      if (!(flags & REPO_NO_LOCATION))
+       repodata_set_location(data, s - pool->solvables, 0, 0, fn);
+      if (S_ISREG(stb.st_mode))
+        repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
+      if (pkgidchk)
        {
          unsigned char pkgid[16];
-         solv_chksum_free(pkgidhandle, pkgid);
+         solv_chksum_free(pkgidchk, pkgid);
          repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
-         pkgidhandle = 0;
+         pkgidchk = 0;
        }
     }
-  if (pkgidhandle)
-    solv_chksum_free(pkgidhandle, 0);
+  if (pkgidchk)
+    solv_chksum_free(pkgidchk, 0);
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
   return s ? s - pool->solvables : 0;
@@ -491,9 +499,9 @@ static char *getsentrynl(struct tarhead *th, char *s, int size)
 }
 
 static Hashtable
-joinhash_init(Repo *repo, Hashmask *hmp)
+joinhash_init(Repo *repo, Hashval *hmp)
 {
-  Hashmask hm = mkmask(repo->nsolvables);
+  Hashval hm = mkmask(repo->nsolvables);
   Hashtable ht = solv_calloc(hm + 1, sizeof(*ht));
   Hashval h, hh;
   Solvable *s;
@@ -512,7 +520,7 @@ joinhash_init(Repo *repo, Hashmask *hmp)
 }
 
 static Solvable *
-joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, const char *fn)
+joinhash_lookup(Repo *repo, Hashtable ht, Hashval hm, const char *fn)
 {
   const char *p;
   Id name, evr;
@@ -592,7 +600,7 @@ adddata(Repodata *data, Solvable *s, struct tarhead *th)
       else if (!strcmp(line, "%GROUPS%"))
        {
          if (getsentrynl(th, line, sizeof(line)))
-           repodata_set_poolstr(data, s - pool->solvables, SOLVABLE_GROUP, line);
+           repodata_add_poolstr_array(data, s - pool->solvables, SOLVABLE_GROUP, line);
        }
       else if (!strcmp(line, "%CSIZE%"))
        {
@@ -625,7 +633,7 @@ adddata(Repodata *data, Solvable *s, struct tarhead *th)
       else if (!strcmp(line, "%LICENSE%"))
        {
          if (getsentrynl(th, line, sizeof(line)))
-           repodata_set_str(data, s - pool->solvables, SOLVABLE_LICENSE, line);
+           repodata_add_poolstr_array(data, s - pool->solvables, SOLVABLE_LICENSE, line);
        }
       else if (!strcmp(line, "%ARCH%"))
        {
@@ -719,7 +727,7 @@ finishsolvable(Repo *repo, Solvable *s)
     return;
   if (!s->name)
     {
-      repo_free_solvable(repo, s - pool->solvables, 1);
+      solvable_free(s, 1);
       return;
     }
   if (!s->arch)
@@ -739,7 +747,7 @@ repo_add_arch_repo(Repo *repo, FILE *fp, int flags)
   int lastdnlen = 0;
   Solvable *s = 0;
   Hashtable joinhash = 0;
-  Hashmask joinhashmask = 0;
+  Hashval joinhashmask = 0;
 
   data = repo_add_repodata(repo, flags);
 
@@ -808,6 +816,8 @@ repo_add_arch_local(Repo *repo, const char *dir, int flags)
 
   data = repo_add_repodata(repo, flags);
 
+  if (flags & REPO_USE_ROOTDIR)
+    dir = pool_prepend_rootdir(pool, dir);
   dp = opendir(dir);
   if (dp)
     {
@@ -841,6 +851,8 @@ repo_add_arch_local(Repo *repo, const char *dir, int flags)
     }
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
+  if (flags & REPO_USE_ROOTDIR)
+    solv_free((char *)dir);
   return 0;
 }