]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
- add pool_error and pool_errstr. get rid of lots of exit() calls.
authorMichael Schroeder <mls@suse.de>
Fri, 13 Apr 2012 17:23:33 +0000 (19:23 +0200)
committerMichael Schroeder <mls@suse.de>
Fri, 13 Apr 2012 17:23:33 +0000 (19:23 +0200)
32 files changed:
examples/solv.c
ext/repo_deb.c
ext/repo_deltainfoxml.c
ext/repo_helix.c
ext/repo_repomdxml.c
ext/repo_rpmdb.c
ext/repo_rpmmd.c
ext/repo_susetags.c
ext/repo_updateinfoxml.c
src/libsolv.ver
src/pool.c
src/pool.h
src/repo_solv.c
tools/archpkgs2solv.c
tools/archrepo2solv.c
tools/common_write.c
tools/comps2solv.c
tools/deltainfoxml2solv.c
tools/diskusagexml2solv.c
tools/dumpsolv.c
tools/findfileconflicts.c
tools/helix2solv.c
tools/installcheck.c
tools/mdk2solv.c
tools/mergesolv.c
tools/patchcheck.c
tools/repomdxml2solv.c
tools/rpmdb2solv.c
tools/rpmmd2solv.c
tools/rpms2solv.c
tools/susetags2solv.c
tools/updateinfoxml2solv.c

index d19939fd82c7389a28f62b153a466ef7382de662..f14d37f78dea497f5282a1eaf98678f7dbefac14 100644 (file)
@@ -1299,6 +1299,7 @@ repomd_load_ext(Repo *repo, Repodata *data)
   struct repoinfo *cinfo;
   const unsigned char *filechksum;
   Id filechksumtype;
+  int r;
 
   cinfo = repo->appdata;
   repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
@@ -1325,10 +1326,15 @@ repomd_load_ext(Repo *repo, Repodata *data)
   if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
     return 0;
   if (!strcmp(ext, "FL"))
-    repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
+    r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
   else if (!strcmp(ext, "DL"))
-    repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
+    r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
   fclose(fp);
+  if (r)
+    {
+      printf("%s\n", pool_errstr(repo->pool));
+      return 0;
+    }
   writecachedrepo(repo, data, ext, cinfo->extcookie);
   return 1;
 }
@@ -1468,7 +1474,12 @@ susetags_load_ext(Repo *repo, Repodata *data)
   filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
   if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
     return 0;
-  repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
+  if (repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES))
+    {
+      fclose(fp);
+      printf("%s\n", pool_errstr(repo->pool));
+      return 0;
+    }
   fclose(fp);
   writecachedrepo(repo, data, ext, cinfo->extcookie);
   return 1;
@@ -1669,24 +1680,42 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
 
 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
-      repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
+      if (repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE))
+       {
+         fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
+         exit(1);
+       }
 # endif
       if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
        {
          Repo *ref = repo_create(pool, "@System.old");
          if (!repo_add_solv(ref, ofp, 0))
            {
-             repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
+             if (repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA))
+               {
+                 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
+                 exit(1);
+               }
              done = 1;
            }
          fclose(ofp);
          repo_free(ref, 1);
        }
       if (!done)
-        repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
+       {
+         if (repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA))
+           {
+             fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
+             exit(1);
+           }
+       }
 #endif
 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
-      repo_add_debdb(repo, 0, REPO_REUSE_REPODATA);
+      if (repo_add_debdb(repo, 0, REPO_REUSE_REPODATA))
+       {
+         fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
+         exit(1);
+       }
 #endif
       writecachedrepo(repo, 0, 0, installedcookie);
     }
@@ -1756,13 +1785,22 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
                }
              fclose(sigfp);
            }
-         repo_add_repomdxml(repo, fp, 0);
+         if (repo_add_repomdxml(repo, fp, 0))
+           {
+             printf("repomd.xml: %s\n", pool_errstr(pool));
+             fclose(fp);
+             break;    /* hopeless */
+           }
          fclose(fp);
          printf(" fetching\n");
          filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
          if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
            {
-             repo_add_rpmmd(repo, fp, 0, 0);
+             if (repo_add_rpmmd(repo, fp, 0, 0))
+               {
+                 printf("primary: %s\n", pool_errstr(pool));
+                 badchecksum = 1;
+               }
              fclose(fp);
            }
          if (badchecksum)
@@ -1771,7 +1809,11 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
          filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
          if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
            {
-             repo_add_updateinfoxml(repo, fp, 0);
+             if (repo_add_updateinfoxml(repo, fp, 0))
+               {
+                 printf("updateinfo: %s\n", pool_errstr(pool));
+                 badchecksum = 1;
+               }
              fclose(fp);
            }
 
@@ -1829,7 +1871,12 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
                  fclose(sigfp);
                }
            }
-         repo_add_content(repo, fp, 0);
+         if (repo_add_content(repo, fp, 0))
+           {
+             printf("content: %s\n", pool_errstr(pool));
+             fclose(fp);
+             break;    /* hopeless */
+           }
          fclose(fp);
          defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
          descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
@@ -1846,7 +1893,12 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
          printf(" fetching\n");
          if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
            break;      /* hopeless */
-         repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES);
+         if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
+           {
+             printf("packages: %s\n", pool_errstr(pool));
+             fclose(fp);
+             break;    /* hopeless */
+           }
          fclose(fp);
          /* add default language */
          filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
@@ -1856,7 +1908,11 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
            {
              if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
                {
-                 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
+                 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
+                   {
+                     printf("packages.en: %s\n", pool_errstr(pool));
+                     badchecksum = 1;
+                   }
                  fclose(fp);
                }
            }
@@ -1877,7 +1933,11 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
                      filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
                      if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
                        {
-                         repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE);
+                         if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
+                           {
+                             printf("%s: %s\n", pbuf, pool_errstr(pool));
+                             badchecksum = 1;
+                           }
                          fclose(fp2);
                        }
                    }
@@ -1947,7 +2007,11 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
                }
              if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
                {
-                 repo_add_debpackages(repo, fp, 0);
+                 if (repo_add_debpackages(repo, fp, 0))
+                   {
+                     printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
+                     badchecksum = 1;
+                   }
                  fclose(fp);
                }
              solv_free((char *)filechksum);
index 38327c6ac6a77cf8b3acd6b174c64e90da829a6d..7e967a700eb8dd82f1f66228e81afb0634dcb8fe 100644 (file)
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <zlib.h>
+#include <errno.h>
 
 #include "pool.h"
 #include "repo.h"
@@ -420,10 +421,7 @@ repo_add_debdb(Repo *repo, const char *rootdir, int flags)
   if (rootdir)
     path = pool_tmpjoin(repo->pool, rootdir, path, 0);
   if ((fp = fopen(path, "r")) == 0)
-    {
-      perror(path);
-      exit(1);
-    }
+    return pool_error(repo->pool, -1, "%s: %s", path, strerror(errno));
   repo_add_debpackages(repo, fp, flags);
   fclose(fp);
   return 0;
index 5e6e86e40d242f00bb8216d0f7d0b30599bb7f03..c841f5edf85935c0e0b09f647b93d27326fded21 100644 (file)
@@ -94,6 +94,7 @@ struct deltarpm {
 };
 
 struct parsedata {
+  int ret;
   int depth;
   enum state state;
   int statedepth;
@@ -296,7 +297,6 @@ startElement(void *userData, const char *name, const char **atts)
     {
 #if 0
       fprintf(stderr, "into unknown: [%d]%s (from: %d)\n", sw->to, name, sw->from);
-      exit( 1 );
 #endif
       return;
     }
@@ -514,8 +514,8 @@ repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
       l = fread(buf, 1, sizeof(buf), fp);
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
-         pool_debug(pool, SOLV_FATAL, "repo_updateinfoxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
-         exit(1);
+         pd.ret = pool_error(pool, -1, "repo_updateinfoxml: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+         break;
        }
       if (l == 0)
        break;
@@ -524,13 +524,14 @@ repo_add_deltainfoxml(Repo *repo, FILE *fp, int flags)
   solv_free(pd.content);
 
   /* now commit all handles */
-  for (i = 0; i < pd.nhandles; i++)
-    repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
+  if (!pd.ret)
+    for (i = 0; i < pd.nhandles; i++)
+      repodata_add_flexarray(pd.data, SOLVID_META, REPOSITORY_DELTAINFO, pd.handles[i]);
   solv_free(pd.handles);
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
-  return 0;
+  return pd.ret;
 }
 
 /* EOF */
index 8e74efa2ba1a607f436ca41ee4d3233b5ea90d93..7415b29d5bc5fbb309796ddeac8788dbe363a52c 100644 (file)
@@ -144,6 +144,7 @@ static struct stateswitch stateswitches[] = {
  */
 
 typedef struct _parsedata {
+  int ret;
   /* XML parser data */
   int depth;
   enum state state;    /* current state */
@@ -865,8 +866,8 @@ repo_add_helix(Repo *repo, FILE *fp, int flags)
       l = fread(buf, 1, sizeof(buf), fp);
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
-         pool_debug(pool, SOLV_FATAL, "%s at line %u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser));
-         exit(1);
+         pd.ret = pool_error(pool, -1, "%s at line %u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser));
+         break;
        }
       if (l == 0)
        break;
@@ -880,5 +881,5 @@ repo_add_helix(Repo *repo, FILE *fp, int flags)
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_helix took %d ms\n", solv_timems(now));
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", repodata_memused(data)/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
-  return 0;
+  return pd.ret;
 }
index faa8456e5d2e013e954e5e9d2e05999971739576..0697aa8335ee698e00acd778e5551d1358c87146 100644 (file)
@@ -150,6 +150,7 @@ static struct stateswitch stateswitches[] = {
 
 
 struct parsedata {
+  int ret;
   int depth;
   enum state state;
   int statedepth;
@@ -306,10 +307,7 @@ startElement(void *userData, const char *name, const char **atts)
         const char *type= find_attr("type", atts);
         pd->chksumtype = type && *type ? solv_chksum_str2type(type) : 0;
        if (!pd->chksumtype)
-         {
-            fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), type ? type : "NULL");
-            exit(1);
-         }
+          pd->ret = pool_error(pd->pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), type ? type : "NULL");
         break;
       }
     default:
@@ -354,12 +352,12 @@ endElement(void *userData, const char *name)
 
     case STATE_CHECKSUM:
     case STATE_OPENCHECKSUM:
+      if (!pd->chksumtype)
+       break;
       if (strlen(pd->content) != 2 * solv_chksum_len(pd->chksumtype))
-       {
-         fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
-         exit(1);
-       }
-      repodata_set_checksum(pd->data, pd->rdhandle, pd->state == STATE_CHECKSUM ? REPOSITORY_REPOMD_CHECKSUM : REPOSITORY_REPOMD_OPENCHECKSUM, pd->chksumtype, pd->content);
+        pd->ret = pool_error(pd->pool, -1, "line %d: invalid checksum length for %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
+      else
+        repodata_set_checksum(pd->data, pd->rdhandle, pd->state == STATE_CHECKSUM ? REPOSITORY_REPOMD_CHECKSUM : REPOSITORY_REPOMD_OPENCHECKSUM, pd->chksumtype, pd->content);
       break;
 
     case STATE_TIMESTAMP:
@@ -486,8 +484,8 @@ repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
       l = fread(buf, 1, sizeof(buf), fp);
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
-         pool_debug(pool, SOLV_FATAL, "repo_repomdxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
-         exit(1);
+         pd.ret = pool_error(pool, -1, "repo_repomdxml: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+         break;
        }
       if (l == 0)
        break;
@@ -498,7 +496,7 @@ repo_add_repomdxml(Repo *repo, FILE *fp, int flags)
     repodata_internalize(data);
 
   free(pd.content);
-  return 0;
+  return pd.ret;
 }
 
 /* EOF */
index 1c6813959f5d9a726bedc8432d295164c7318105..c66c6f012a435f3d36ca44a542fd786c1224aa46 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include <stdint.h>
+#include <errno.h>
 
 #include <rpm/rpmio.h>
 #include <rpm/rpmpgp.h>
@@ -316,7 +317,7 @@ static char *headtoevr(RpmHead *h)
   if (!version || !release)
     {
       fprintf(stderr, "headtoevr: bad rpm header\n");
-      exit(1);
+      return 0;
     }
   for (v = version; *v >= '0' && *v <= '9'; v++)
     ;
@@ -460,7 +461,7 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf,
   if (nc != vc || nc != fc)
     {
       fprintf(stderr, "bad dependency entries\n");
-      exit(1);
+      return 0;
     }
 
   cc = nc;
@@ -747,7 +748,7 @@ addfileprovides(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rp
   if (bnc != dic)
     {
       fprintf(stderr, "bad filelist\n");
-      exit(1);
+      return olddeps;
     }
 
   if (data)
@@ -879,7 +880,7 @@ rpm2solv(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead,
   if (!s->name)
     {
       fprintf(stderr, "package has no name\n");
-      exit(1);
+      return 0;
     }
   sourcerpm = headstring(rpmhead, TAG_SOURCERPM);
   if (sourcerpm)
@@ -1369,17 +1370,17 @@ count_headers(const char *rootdir, DB_ENV *dbenv)
   if (db_create(&db, dbenv, 0))
     {
       perror("db_create");
-      exit(1);
+      return 0;
     }
   if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
     {
       perror("db->open Name index");
-      exit(1);
+      return 0;
     }
   if (db->cursor(db, NULL, &dbc, 0))
     {
       perror("db->cursor");
-      exit(1);
+      return 0;
     }
   while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
     count += dbdata.size / RPM_INDEX_SIZE;
@@ -1436,14 +1437,15 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
     ref = 0;
 
   if (!(dbenv = opendbenv(rootdir)))
-    exit(1);
+    {
+      return pool_error(pool, -1, "repo_add_rpmdb: opendbenv failed");
+    }
 
   /* XXX: should get ro lock of Packages database! */
   snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir);
   if (stat(dbpath, &packagesstat))
     {
-      perror(dbpath);
-      exit(1);
+      return pool_error(pool, -1, "repo_add_rpmdb: %s: %s", dbpath, strerror(errno));
     }
   mkrpmdbcookie(&packagesstat, newcookie);
   repodata_set_bin_checksum(data, SOLVID_META, REPOSITORY_RPMDBCOOKIE, REPOKEY_TYPE_SHA256, newcookie);
@@ -1459,23 +1461,28 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
        count = count_headers(rootdir, dbenv);
       if (db_create(&db, dbenv, 0))
        {
-         perror("db_create");
-         exit(1);
+         pool_error(pool, -1, "repo_add_rpmdb: db_create: %s", strerror(errno));
+         dbenv->close(dbenv, 0);
+         return -1;
        }
       if (db->open(db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
        {
-         perror("db->open Packages index");
-         exit(1);
+         pool_error(pool, -1, "repo_add_rpmdb: db->open Packages index failed: %s", strerror(errno));
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return -1;
        }
       if (db->get_byteswapped(db, &byteswapped))
        {
-         perror("db->get_byteswapped");
-         exit(1);
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return pool_error(pool, -1, "repo_add_rpmdb: db->get_byteswapped failed");
        }
       if (db->cursor(db, NULL, &dbc, 0))
        {
-         perror("db->cursor");
-         exit(1);
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return pool_error(pool, -1, "repo_add_rpmdb: db->cursor failed");
        }
       rpmheadsize = 0;
       rpmhead = 0;
@@ -1494,16 +1501,20 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
            repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
           if (dbkey.size != 4)
            {
-             fprintf(stderr, "corrupt Packages database (key size)\n");
-             exit(1);
+             dbc->c_close(dbc);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "corrupt Packages database (key size)");
            }
          dbid = db2rpmdbid(dbkey.data, byteswapped);
          if (dbid == 0)                /* the join key */
            continue;
          if (dbdata.size < 8)
            {
-             fprintf(stderr, "corrupt rpm database (size %u)\n", dbdata.size);
-             exit(1);
+             dbc->c_close(dbc);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "corrupt rpm database (size %u)\n", dbdata.size);
            }
          if (dbdata.size > rpmheadsize)
            {
@@ -1515,8 +1526,10 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
          rpmhead->dcnt = buf[4] << 24  | buf[5] << 16  | buf[6] << 8 | buf[7];
          if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
            {
-             fprintf(stderr, "corrupt rpm database (data size)\n");
-             exit(1);
+             dbc->c_close(dbc);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "corrupt rpm database (data size)\n");
            }
          memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
          rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
@@ -1577,23 +1590,28 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
       memset(dircache, 0, sizeof(dircache));
       if (db_create(&db, dbenv, 0))
        {
-         perror("db_create");
-         exit(1);
+         pool_error(pool, -1, "repo_add_rpmdb: db_create: %s", strerror(errno));
+         dbenv->close(dbenv, 0);
+         return -1;
        }
       if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
        {
-         perror("db->open Name index");
-         exit(1);
+         pool_error(pool, -1, "repo_add_rpmdb: db->open Name index failed: %s", strerror(errno));
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return -1;
        }
       if (db->get_byteswapped(db, &byteswapped))
        {
-         perror("db->get_byteswapped");
-         exit(1);
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return pool_error(pool, -1, "repo_add_rpmdb: db->get_byteswapped failed");
        }
       if (db->cursor(db, NULL, &dbc, 0))
        {
-         perror("db->cursor");
-         exit(1);
+         db->close(db, 0);
+         dbenv->close(dbenv, 0);
+         return pool_error(pool, -1, "repo_add_rpmdb: db->cursor failed");
        }
       nrpmids = 0;
       rpmids = 0;
@@ -1691,18 +1709,22 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
            {
              if (db_create(&db, dbenv, 0))
                {
-                 perror("db_create");
-                 exit(1);
+                 pool_error(pool, -1, "repo_add_rpmdb: db_create: %s", strerror(errno));
+                 dbenv->close(dbenv, 0);
+                 return -1;
                }
              if (db->open(db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
                {
-                 perror("db->open var/lib/rpm/Packages");
-                 exit(1);
+                 pool_error(pool, -1, "repo_add_rpmdb: db->open Packages index failed: %s", strerror(errno));
+                 db->close(db, 0);
+                 dbenv->close(dbenv, 0);
+                 return -1;
                }
              if (db->get_byteswapped(db, &byteswapped))
                {
-                 perror("db->get_byteswapped");
-                 exit(1);
+                 db->close(db, 0);
+                 dbenv->close(dbenv, 0);
+                 return pool_error(pool, -1, "repo_add_rpmdb: db->get_byteswapped failed");
                }
            }
           rpmdbid2db(buf, rp->dbid, byteswapped);
@@ -1712,15 +1734,15 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
          dbdata.size = 0;
          if (db->get(db, NULL, &dbkey, &dbdata, 0))
            {
-             perror("db->get");
-             fprintf(stderr, "corrupt rpm database, key %d not found\n", dbid);
-             fprintf(stderr, "please run 'rpm --rebuilddb' to recreate the database index files\n");
-             exit(1);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "inconsistent rpm database, key %d not found. run 'rpm --rebuilddb' to fix.", dbid);
            }
          if (dbdata.size < 8)
            {
-             fprintf(stderr, "corrupt rpm database (size)\n");
-             exit(1);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "corrupt Packages database (size)");
            }
          if (dbdata.size > rpmheadsize)
            {
@@ -1732,8 +1754,9 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
          rpmhead->dcnt = buf[4] << 24  | buf[5] << 16  | buf[6] << 8 | buf[7];
          if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
            {
-             fprintf(stderr, "corrupt rpm database (data size)\n");
-             exit(1);
+             db->close(db, 0);
+             dbenv->close(dbenv, 0);
+             return pool_error(pool, -1, "corrupt Packages database (data size)");
            }
          memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
          rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
@@ -2191,6 +2214,8 @@ rpm_query(void *rpmhandle, Id what)
       if (!arch)
        arch = "noarch";
       evr = headtoevr(rpmhead);
+      if (!evr)
+       break;
       l = strlen(name) + 1 + strlen(evr) + 1 + strlen(arch) + 1;
       r = solv_malloc(l);
       sprintf(r, "%s-%s.%s", name, evr, arch);
index efde4fde76b1503d53ee0e16e00ec9665fa2ee46..80e54c638dc4c406bc4dcb5081bcc67a074bcecd 100644 (file)
@@ -230,6 +230,7 @@ static struct stateswitch stateswitches[] = {
 #define CSREALLOC_STEP 1024
 
 struct parsedata {
+  int ret;
   Pool *pool;
   Repo *repo;
   Repodata *data;
@@ -678,6 +679,10 @@ startElement(void *userData, const char *name, const char **atts)
   pd->statedepth = pd->depth;
   pd->lcontent = 0;
   *pd->content = 0;
+
+  if (!s && pd->state != STATE_SOLVABLE)
+    return;
+
   switch(pd->state)
     {
     case STATE_SOLVABLE:
@@ -711,8 +716,10 @@ startElement(void *userData, const char *name, const char **atts)
           Id index = stringpool_str2id(&pd->cspool, pkgid, 0);
           if (!index || index >= pd->ncscache || !pd->cscache[index])
            {
-              fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
-              exit(1);
+              pool_debug(pool, SOLV_WARN, "the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid);
+             pd->solvable = 0;
+             pd->handle = 0;
+             break;
            }
          pd->solvable = pool_id2solvable(pool, pd->cscache[index]);
         }
@@ -818,12 +825,9 @@ startElement(void *userData, const char *name, const char **atts)
        const char *tmp = find_attr("type", atts);
        pd->chksumtype = tmp && *tmp ? solv_chksum_str2type(tmp) : 0;
         if (!pd->chksumtype)
-         {
-           fprintf(stderr, "Unknown checksum type: %d: %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), tmp ? tmp: "NULL");
-            exit(1);
-         }
+         pd->ret = pool_error(pool, -1, "line %d: unknown checksum type: %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), tmp ? tmp: "NULL");
+        break;
       }
-      break;
     case STATE_TIME:
       {
         unsigned int t;
@@ -853,6 +857,7 @@ startElement(void *userData, const char *name, const char **atts)
         str = find_attr("end", atts);
        if (str && (end = atoi(str)) != 0)
          repodata_set_num(pd->data, handle, SOLVABLE_HEADEREND, end);
+       break;
       }
       /*
         <diskusage>
@@ -867,7 +872,7 @@ startElement(void *userData, const char *name, const char **atts)
       */
     case STATE_DISKUSAGE:
       {
-        /* Really, do nothing, wat for <dir> tag */
+        /* Really, do nothing, wait for <dir> tag */
         break;
       }
     case STATE_DIR:
@@ -878,8 +883,7 @@ startElement(void *userData, const char *name, const char **atts)
           dirid = repodata_str2dir(pd->data, str, 1);
         else
           {
-            fprintf( stderr, "<dir .../> tag without 'name' attribute, atts = %p, *atts = %p\n",
-                    (void *)atts, *atts);
+           pd->ret = pool_error(pool, -1, "<dir .../> tag without 'name' attribute");
             break;
           }
         if ((str = find_attr("size", atts)) != 0)
@@ -937,6 +941,15 @@ endElement(void *userData, const char *name)
 
   pd->depth--;
   pd->statedepth--;
+
+
+  if (!s)
+    {
+      pd->state = pd->sbtab[pd->state];
+      pd->docontent = 0;
+      return;
+    }
+
   switch (pd->state)
     {
     case STATE_SOLVABLE:
@@ -952,6 +965,7 @@ endElement(void *userData, const char *name)
       s->conflicts = repo_fix_conflicts(repo, s->conflicts);
       pd->freshens = 0;
       pd->kind = 0;
+      pd->solvable = s = 0;
       break;
     case STATE_NAME:
       if (pd->kind)
@@ -975,10 +989,12 @@ endElement(void *userData, const char *name)
       {
         Id index;
        
+       if (!pd->chksumtype)
+         break;
         if (strlen(pd->content) != 2 * solv_chksum_len(pd->chksumtype))
           {
-            fprintf(stderr, "Invalid checksum length: %d: for %s\n", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
-            exit(1);
+           pd->ret = pool_error(pool, -1, "line %d: invalid checksum length for %s", (unsigned int)XML_GetCurrentLineNumber(*pd->parser), solv_chksum_type2str(pd->chksumtype));
+           break;
           }
         repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, pd->chksumtype, pd->content);
         /* we save the checksum to solvable id relationship for extended
@@ -1210,8 +1226,8 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
       l = fread(buf, 1, sizeof(buf), fp);
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
-         pool_debug(pool, SOLV_FATAL, "repo_rpmmd: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
-         exit(1);
+         pd.ret = pool_error(pool, -1, "repo_rpmmd: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+         break;
        }
       if (l == 0)
        break;
@@ -1229,5 +1245,5 @@ repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags)
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmmd took %d ms\n", solv_timems(now));
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
   POOL_DEBUG(SOLV_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", repodata_memused(data)/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
-  return 0;
+  return pd.ret;
 }
index 501916eb0f420d89fff1332ab64d54df664d1131..5ed8d9f7c9bfc24409abf8e58f8affea88aee1ee 100644 (file)
@@ -26,6 +26,7 @@ struct datashare {
 };
 
 struct parsedata {
+  int ret;
   Pool *pool;
   Repo *repo;
   Repodata *data;
@@ -91,8 +92,8 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma
       i = split(line + 6, sp, 4); /* name, <op>, evr, ? */
       if (i != 1 && i != 3) /* expect either 'name' or 'name' <op> 'evr' */
         {
-         pool_debug(pool, SOLV_FATAL, "susetags: bad dependency line: %d: %s\n", pd->lineno, line);
-          exit(1);
+         pd->ret = pool_error(pool, -1, "susetags: line %d: bad dependency: '%s'\n", pd->lineno, line);
+          return olddeps;
         }
       if (kind)
         id = pool_str2id(pool, join2(&pd->jd, kind, ":", sp[0]), 1);
@@ -110,8 +111,8 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id ma
                flags = 4;
              else
                {
-                 pool_debug(pool, SOLV_FATAL, "susetags: unknown relation in %d: '%s'\n", pd->lineno, sp[1]);
-                 exit(1);
+                 pd->ret = pool_error(pool, -1, "susetags: line %d: unknown relation: '%s'\n", pd->lineno, sp[1]);
+                 return olddeps;
                }
             }
           id = pool_rel2id(pool, id, evrid, flags + 1, 1);
@@ -138,8 +139,8 @@ add_source(struct parsedata *pd, char *line, Solvable *s, Id handle)
 
   if (split(line, sp, 5) != 4)
     {
-      pool_debug(pool, SOLV_FATAL, "susetags: bad source line: %d: %s\n", pd->lineno, line);
-      exit(1);
+      pd->ret = pool_error(pool, -1, "susetags: line %d: bad source line '%s'\n", pd->lineno, line);
+      return;
     }
 
   name = pool_str2id(pool, sp[0], 1);
@@ -197,19 +198,19 @@ set_checksum(struct parsedata *pd, Repodata *data, Id handle, Id keyname, char *
   Id type;
   if (split(line, sp, 3) != 2)
     {
-      pool_debug(pd->repo->pool, SOLV_FATAL, "susetags: bad checksum line: %d: %s\n", pd->lineno, line);
-      exit(1);
+      pd->ret = pool_error(pd->pool, -1, "susetags: line %d: bad checksum line '%s'\n", pd->lineno, line);
+      return;
     }
   type = solv_chksum_str2type(sp[0]);
   if (!type)
     {
-      pool_debug(pd->repo->pool, SOLV_FATAL, "susetags: unknown checksum type: %d: %s\n", pd->lineno, sp[0]);
-      exit(1);
+      pd->ret = pool_error(pd->pool, -1, "susetags: line %d: unknown checksum type: '%s'\n", pd->lineno, sp[0]);
+      return;
     }
   if (strlen(sp[1]) != 2 * solv_chksum_len(type))
     {
-      pool_debug(pd->repo->pool, SOLV_FATAL, "susetags: bad checksum length: %d: for %s: %s\n", pd->lineno, sp[0], sp[1]);
-      exit(1);
+      pd->ret = pool_error(pd->pool, -1, "susetags: line %d: bad checksum length for type %s: '%s'\n", pd->lineno, sp[0], sp[1]);
+      return;
     }
   repodata_set_checksum(data, handle, keyname, type, sp[1]);
 }
@@ -603,6 +604,9 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
       char *olinep; /* old line pointer */
       char line_lang[6];
       int keylen = 3;
+
+      if (pd.ret)
+       break;
       if (linep - line + 16 > aline)              /* (re-)alloc buffer */
        {
          aline = linep - line;
@@ -663,8 +667,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
          char *tagend = strchr(line, ':');
          if (!tagend)
            {
-             pool_debug(pool, SOLV_FATAL, "susetags: bad line: %d: %s\n", pd.lineno, line);
-             exit(1);
+             pd.ret = pool_error(pool, -1, "susetags: line %d: bad line '%s'\n", pd.lineno, line);
+             break;
            }
          intag = tagend - (line + 1);
          cummulate = 0;
@@ -739,8 +743,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
                int i = split(line + 6, sp, 3);
                if (i != 2 && i != 3)
                  {
-                   pool_debug(pool, SOLV_FATAL, "susetags: bad location line: %d: %s\n", pd.lineno, line);
-                   exit(1);
+                   pd.ret = pool_error(pool, -1, "susetags: line %d: bad location line '%s'\n", pd.lineno, line);
+                   continue;
                  }
                set_delta_location(data, handle, atoi(sp[0]), i == 3 ? sp[2] : 0, sp[1]);
                continue;
@@ -775,8 +779,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
          pd.kind = 0;
           if (split(line + 5, sp, 5) != 4)
            {
-             pool_debug(pool, SOLV_FATAL, "susetags: bad line: %d: %s\n", pd.lineno, line);
-             exit(1);
+             pd.ret = pool_error(pool, -1, "susetags: line %d: bad line '%s'\n", pd.lineno, line);
+             break;
            }
          handle = repodata_new_handle(data);
          repodata_set_id(data, handle, DELTA_PACKAGE_NAME, pool_str2id(pool, sp[0], 1));
@@ -808,8 +812,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
 
           if (split(line + 5, sp, 5) != 4)
            {
-             pool_debug(pool, SOLV_FATAL, "susetags: bad line: %d: %s\n", pd.lineno, line);
-             exit(1);
+             pd.ret = pool_error(pool, -1, "susetags: line %d: bad line '%s'\n", pd.lineno, line);
+             break;
            }
          s = 0;
           freshens = 0;
@@ -978,8 +982,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
              int i = split(line + 6, sp, 3);
              if (i != 2 && i != 3)
                {
-                 pool_debug(pool, SOLV_FATAL, "susetags: bad location line: %d: %s\n", pd.lineno, line);
-                 exit(1);
+                 pd.ret = pool_error(pool, -1, "susetags: line %d: bad location line '%s'\n", pd.lineno, line);
+                 continue;
                }
              repodata_set_location(data, handle, atoi(sp[0]), i == 3 ? sp[2] : pool_id2str(pool, s->arch), sp[1]);
            }
@@ -1036,8 +1040,8 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
              Id name, evr, arch;
              if (split(line + 6, sp, 5) != 4)
                {
-                 pool_debug(pool, SOLV_FATAL, "susetags: bad =Shr line: %s\n", line + 6);
-                 exit(1);
+                 pd.ret = pool_error(pool, -1, "susetags: line %d: bad =Shr line '%s'\n", pd.lineno, line);
+                 continue;
                }
              name = pool_str2id(pool, sp[0], 1);
              evr = toevr(pool, &pd, sp[1], sp[2]);
@@ -1139,7 +1143,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
            break;
 
          default:
-           pool_debug(pool, SOLV_ERROR, "susetags: unknown line: %d: %s\n", pd.lineno, line);
+           pool_debug(pool, SOLV_WARN, "susetags: unknown line: %d: %s\n", pd.lineno, line);
            break;
        }
 
@@ -1211,5 +1215,5 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int
   solv_free(pd.language);
   solv_free(line);
   join_freemem(&pd.jd);
-  return 0;
+  return pd.ret;
 }
index dc8f392232f102edb0ad0876e6e5afc5ed78127f..59e9b172a79153c624febc7ba0f9d4245d5800c3 100644 (file)
@@ -111,6 +111,7 @@ static struct stateswitch stateswitches[] = {
 };
 
 struct parsedata {
+  int ret;
   int depth;
   enum state state;
   int statedepth;
@@ -262,7 +263,6 @@ startElement(void *userData, const char *name, const char **atts)
     {
 #if 0
       fprintf(stderr, "into unknown: %s (from: %d)\n", name, pd->state);
-      exit( 1 );
 #endif
       return;
     }
@@ -637,8 +637,8 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
       l = fread(buf, 1, sizeof(buf), fp);
       if (XML_Parse(parser, buf, l, l == 0) == XML_STATUS_ERROR)
        {
-         pool_debug(pool, SOLV_FATAL, "repo_updateinfoxml: %s at line %u:%u\n", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
-         exit(1);
+         pd.ret = pool_error(pool, -1, "repo_updateinfoxml: %s at line %u:%u", XML_ErrorString(XML_GetErrorCode(parser)), (unsigned int)XML_GetCurrentLineNumber(parser), (unsigned int)XML_GetCurrentColumnNumber(parser));
+         break;
        }
       if (l == 0)
        break;
@@ -649,6 +649,6 @@ repo_add_updateinfoxml(Repo *repo, FILE *fp, int flags)
 
   if (!(flags & REPO_NO_INTERNALIZE))
     repodata_internalize(data);
-  return 0;
+  return pd.ret;
 }
 
index 78f6d354b28a600051369c2ef7d55a6e7565dd25..a2e100c609a1696cb0c5c96832c8ff91f4e41f42 100644 (file)
@@ -54,6 +54,8 @@ SOLV_1.0 {
                pool_createwhatprovides;
                pool_debug;
                pool_dep2str;
+               pool_error;
+               pool_errstr;
                pool_evrcmp;
                pool_evrcmp_str;
                pool_evrmatch;
index 4a1383cfcbef92a2b3cee9e2ecb237bfa092fe4f..f8656b4a24011caa43b70c524a2f27bba745801f 100644 (file)
@@ -109,6 +109,7 @@ pool_free(Pool *pool)
     free((char *)pool->languages[i]);
   solv_free(pool->languages);
   solv_free(pool->languagecache);
+  solv_free(pool->errstr);
   solv_free(pool);
 }
 
@@ -871,15 +872,56 @@ pool_debug(Pool *pool, int type, const char *format, ...)
       return;
     }
   vsnprintf(buf, sizeof(buf), format, args);
+  va_end(args);
   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
 }
 
+int
+pool_error(Pool *pool, int ret, const char *format, ...)
+{
+  va_list args;
+  int l;
+  va_start(args, format);
+  if (!pool->errstr)
+    {
+      pool->errstra = 1024;
+      pool->errstr = solv_malloc(pool->errstra);
+    }
+  if (!*format)
+    {
+      *pool->errstr = 0;
+      l = 0;
+    }
+  else
+    l = vsnprintf(pool->errstr, pool->errstra, format, args);
+  va_end(args);
+  if (l >= 0 && l + 1 > pool->errstra)
+    {
+      pool->errstra = l + 256;
+      pool->errstr = solv_realloc(pool->errstr, pool->errstra);
+      va_start(args, format);
+      l = vsnprintf(pool->errstr, pool->errstra, format, args);
+      va_end(args);
+    }
+  if (l < 0)
+    strcpy(pool->errstr, "unknown error");
+  if (pool->debugmask & SOLV_ERROR)
+    pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
+  return ret;
+}
+
+char *
+pool_errstr(Pool *pool)
+{
+  return pool->errstr ? pool->errstr : "no error";
+}
+
 void
 pool_setdebuglevel(Pool *pool, int level)
 {
   int mask = SOLV_DEBUG_RESULT;
   if (level > 0)
-    mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
+    mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
   if (level > 1)
     mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
   if (level > 2)
index 79d4183d6dc126cf5bb1facbeee7e45bbe9b478f..a1359a8979a411a7e23ace81ed8b5d7f63d09d3c 100644 (file)
@@ -140,6 +140,9 @@ struct _Pool {
 
   /* our tmp space string space */
   struct _Pool_tmpspace tmpspace;
+
+  char *errstr;                        /* last error string */
+  int errstra;                 /* allocated space for errstr */
 #endif
 
 };
@@ -225,6 +228,9 @@ extern const char *pool_bin2hex(Pool *pool, const unsigned char *buf, int len);
 
 extern void pool_set_installed(Pool *pool, struct _Repo *repo);
 
+extern int  pool_error(Pool *pool, int ret, const char *format, ...) __attribute__((format(printf, 3, 4)));
+extern char *pool_errstr(Pool *pool);
+
 /**
  * Solvable management
  */
index 3f391ef3c4a271bb063f11c3d407460e91a9a094..84e4835c6bcaf14e89e08b87cf3c5bcd458e8a25 100644 (file)
@@ -60,8 +60,7 @@ read_u32(Repodata *data)
       c = getc(data->fp);
       if (c == EOF)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
-         data->error = SOLV_ERROR_EOF;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_EOF, "unexpected EOF");
          return 0;
        }
       x = (x << 8) | c;
@@ -84,8 +83,7 @@ read_u8(Repodata *data)
   c = getc(data->fp);
   if (c == EOF)
     {
-      pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
-      data->error = SOLV_ERROR_EOF;
+      data->error = pool_error(data->repo->pool, SOLV_ERROR_EOF, "unexpected EOF");
       return 0;
     }
   return c;
@@ -109,8 +107,7 @@ read_id(Repodata *data, Id max)
       c = getc(data->fp);
       if (c == EOF)
        {
-          pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
-         data->error = SOLV_ERROR_EOF;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_EOF, "unexpected EOF");
          return 0;
        }
       if (!(c & 128))
@@ -118,16 +115,14 @@ read_id(Repodata *data, Id max)
          x = (x << 7) | c;
          if (max && x >= max)
            {
-              pool_debug(data->repo->pool, SOLV_ERROR, "read_id: id too large (%u/%u)\n", x, max);
-             data->error = SOLV_ERROR_ID_RANGE;
+             data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_id: id too large (%u/%u)", x, max);
              return 0;
            }
          return x;
        }
       x = (x << 7) ^ c ^ 128;
     }
-  pool_debug(data->repo->pool, SOLV_ERROR, "read_id: id too long\n");
-  data->error = SOLV_ERROR_CORRUPT;
+  data->error = pool_error(data->repo->pool, SOLV_ERROR_CORRUPT, "read_id: id too long");
   return 0;
 }
 
@@ -145,8 +140,7 @@ read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
       c = getc(data->fp);
       if (c == EOF)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
-         data->error = SOLV_ERROR_EOF;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_EOF, "unexpected EOF");
          return 0;
        }
       if ((c & 128) != 0)
@@ -157,15 +151,14 @@ read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
       x = (x << 6) | (c & 63);
       if (max && x >= max)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
-         data->error = SOLV_ERROR_ID_RANGE;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "read_idarray: id too large (%u/%u)", x, max);
          return 0;
        }
       if (map)
        x = map[x];
       if (store == end)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: array overflow\n");
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_OVERFLOW, "read_idarray: array overflow");
          return 0;
        }
       *store++ = x;
@@ -175,8 +168,7 @@ read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
            return store;
          if (store == end)
            {
-             pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: array overflow\n");
-             data->error = SOLV_ERROR_OVERFLOW;
+             data->error = pool_error(data->repo->pool, SOLV_ERROR_OVERFLOW, "read_idarray: array overflow");
              return 0;
            }
          *store++ = 0;
@@ -202,8 +194,7 @@ data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, Repodata *data)
   dp = data_read_id(dp, &x);
   if (x < 0 || (max && x >= max))
     {
-      pool_debug(data->repo->pool, SOLV_ERROR, "data_read_id_max: id too large (%u/%u)\n", x, max);
-      data->error = SOLV_ERROR_ID_RANGE;
+      data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_id_max: id too large (%u/%u)", x, max);
       x = 0;
     }
   *ret = map ? map[x] : x;
@@ -228,7 +219,7 @@ data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata *da
       x = (x << 6) | (c & 63);
       if (max && x >= max)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_idarray: id too large (%u/%u)", x, max);
          data->error = SOLV_ERROR_ID_RANGE;
          break;
        }
@@ -272,8 +263,7 @@ data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata
       old = x;
       if (max && x >= max)
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
-         data->error = SOLV_ERROR_ID_RANGE;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "data_read_rel_idarray: id too large (%u/%u)", x, max);
          break;
        }
       *store++ = map ? map[x] : x;
@@ -393,8 +383,7 @@ incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
       dp = data_read_ideof(dp, &id, &eof);
       if (id < 0 || (max && id >= max))
        {
-         pool_debug(data->repo->pool, SOLV_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
-         data->error = SOLV_ERROR_ID_RANGE;
+         data->error = pool_error(data->repo->pool, SOLV_ERROR_ID_RANGE, "incore_map_idarray: id too large (%u/%u)", id, max);
          break;
        }
       id = map[id];
@@ -521,18 +510,14 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
   repopagestore_init(&data.store);
 
   if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
-    {
-      pool_debug(pool, SOLV_ERROR, "not a SOLV file\n");
-      return SOLV_ERROR_NOT_SOLV;
-    }
+     return pool_error(pool, SOLV_ERROR_NOT_SOLV, "not a SOLV file");
   solvversion = read_u32(&data);
   switch (solvversion)
     {
       case SOLV_VERSION_8:
        break;
       default:
-        pool_debug(pool, SOLV_ERROR, "unsupported SOLV version\n");
-        return SOLV_ERROR_UNSUPPORTED;
+        return pool_error(pool, SOLV_ERROR_UNSUPPORTED, "unsupported SOLV version");
     }
 
   numid = read_u32(&data);
@@ -544,30 +529,18 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
   solvflags = read_u32(&data);
 
   if (numdir && numdir < 2)
-    {
-      pool_debug(pool, SOLV_ERROR, "bad number of dirs\n");
-      return SOLV_ERROR_CORRUPT;
-    }
+    return pool_error(pool, SOLV_ERROR_CORRUPT, "bad number of dirs");
 
   if (numrel && (flags & REPO_LOCALPOOL) != 0)
-    {
-      pool_debug(pool, SOLV_ERROR, "relations are forbidden in a local pool\n");
-      return SOLV_ERROR_CORRUPT;
-    }
+    return pool_error(pool, SOLV_ERROR_CORRUPT, "relations are forbidden in a local pool");
   if ((flags & REPO_EXTEND_SOLVABLES) && numsolv)
     {
       /* make sure that we exactly replace the stub repodata */
       if (extendend - extendstart != numsolv)
-       {
-         pool_debug(pool, SOLV_ERROR, "sub-repository solvable number does not match main repository (%d - %d)\n", extendend - extendstart, numsolv);
-         return SOLV_ERROR_CORRUPT;
-       }
+       return pool_error(pool, SOLV_ERROR_CORRUPT, "sub-repository solvable number does not match main repository (%d - %d)", extendend - extendstart, numsolv);
       for (i = 0; i < numsolv; i++)
        if (pool->solvables[extendstart + i].repo != repo)
-         {
-           pool_debug(pool, SOLV_ERROR, "main repository contains holes, cannot extend\n");
-           return SOLV_ERROR_CORRUPT;
-         }
+         return pool_error(pool, SOLV_ERROR_CORRUPT, "main repository contains holes, cannot extend");
     }
 
   /*******  Part 1: string IDs  *****************************************/
@@ -615,10 +588,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
   if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
     {
       if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
-       {
-         pool_debug(pool, SOLV_ERROR, "read error while reading strings\n");
-         return SOLV_ERROR_EOF;
-       }
+        return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
     }
   else
     {
@@ -631,9 +601,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
 
       if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
         {
-         pool_debug(pool, SOLV_ERROR, "read error while reading strings\n");
          solv_free(prefix);
-         return SOLV_ERROR_EOF;
+          return pool_error(pool, SOLV_ERROR_EOF, "read error while reading strings");
        }
       for (i = 1; i < numid; i++)
         {
@@ -642,9 +611,8 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
          freesp -= same + len;
          if (freesp < 0)
            {
-             pool_debug(pool, SOLV_ERROR, "overflow while expanding strings\n");
              solv_free(prefix);
-             return SOLV_ERROR_OVERFLOW;
+             return pool_error(pool, SOLV_ERROR_OVERFLOW, "overflow while expanding strings");
            }
          if (same)
            memcpy(dest, old_str, same);
@@ -655,10 +623,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
        }
       solv_free(prefix);
       if (freesp != 0)
-       {
-         pool_debug(pool, SOLV_ERROR, "expanding strings size mismatch\n");
-         return SOLV_ERROR_CORRUPT;
-       }
+       return pool_error(pool, SOLV_ERROR_CORRUPT, "expanding strings size mismatch");
     }
   strsp[sizeid] = 0;                  /* make string space \0 terminated */
   sp = strsp;
@@ -672,16 +637,12 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
       if (*sp)
        {
          /* we need the '' for directories */
-         pool_debug(pool, SOLV_ERROR, "store strings don't start with ''\n");
-         return SOLV_ERROR_CORRUPT;
+         return pool_error(pool, SOLV_ERROR_CORRUPT, "store strings don't start with an empty string");
        }
       for (i = 1; i < spool->nstrings; i++)
        {
          if (sp >= strsp + sizeid)
-           {
-             pool_debug(pool, SOLV_ERROR, "not enough strings\n");
-             return SOLV_ERROR_OVERFLOW;
-           }
+           return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings");
          str[i] = sp - spool->stringspace;
          sp += strlen(sp) + 1;
        }
@@ -729,8 +690,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
            {
              solv_free(hashtbl);
              solv_free(idmap);
-             pool_debug(pool, SOLV_ERROR, "not enough strings %d %d\n", i, numid);
-             return SOLV_ERROR_OVERFLOW;
+             return pool_error(pool, SOLV_ERROR_OVERFLOW, "not enough strings %d %d", i, numid);
            }
          if (!*sp)                            /* empty string */
            {
@@ -907,8 +867,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
         type = pool_str2id(pool, stringpool_id2str(spool, type), 1);
       if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
        {
-         pool_debug(pool, SOLV_ERROR, "unsupported data type '%s'\n", pool_id2str(pool, type));
-         data.error = SOLV_ERROR_UNSUPPORTED;
+         data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "unsupported data type '%s'", pool_id2str(pool, type));
          type = REPOKEY_TYPE_VOID;
        }
       keys[i].name = id;
@@ -919,31 +878,19 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
       if (keys[i].storage == KEY_STORAGE_SOLVABLE)
        keys[i].storage = KEY_STORAGE_INCORE;
       if (keys[i].storage != KEY_STORAGE_INCORE && keys[i].storage != KEY_STORAGE_VERTICAL_OFFSET)
-       {
-         pool_debug(pool, SOLV_ERROR, "unsupported storage type %d\n", keys[i].storage);
-         data.error = SOLV_ERROR_UNSUPPORTED;
-       }
+       data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "unsupported storage type %d", keys[i].storage);
       if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
        {
          if (keys[i].storage != KEY_STORAGE_INCORE)
-           {
-             pool_debug(pool, SOLV_ERROR, "main solvable data must use incore storage%d\n", keys[i].storage);
-             data.error = SOLV_ERROR_UNSUPPORTED;
-           }
+           data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "main solvable data must use incore storage %d", keys[i].storage);
          keys[i].storage = KEY_STORAGE_SOLVABLE;
        }
       /* cannot handle rel idarrays in incore/vertical */
       if (type == REPOKEY_TYPE_REL_IDARRAY && keys[i].storage != KEY_STORAGE_SOLVABLE)
-       {
-         pool_debug(pool, SOLV_ERROR, "type REL_IDARRAY is only supported for STORAGE_SOLVABLE\n");
-         data.error = SOLV_ERROR_UNSUPPORTED;
-       }
+       data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "type REL_IDARRAY is only supported for STORAGE_SOLVABLE");
       /* cannot handle mapped ids in vertical */
       if (!(flags & REPO_LOCALPOOL) && keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET && (type == REPOKEY_TYPE_ID || type == REPOKEY_TYPE_IDARRAY))
-       {
-         pool_debug(pool, SOLV_ERROR, "mapped ids are not supported for STORAGE_VERTICAL_OFFSET\n");
-         data.error = SOLV_ERROR_UNSUPPORTED;
-       }
+       data.error = pool_error(pool, SOLV_ERROR_UNSUPPORTED, "mapped ids are not supported for STORAGE_VERTICAL_OFFSET");
  
       if (keys[i].type == REPOKEY_TYPE_CONSTANTID && idmap)
        keys[i].size = idmap[keys[i].size];
@@ -1012,8 +959,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
     l = allsize;
   if (!l || fread(buf, l, 1, data.fp) != 1)
     {
-      pool_debug(pool, SOLV_ERROR, "unexpected EOF\n");
-      data.error = SOLV_ERROR_EOF;
+      data.error = pool_error(pool, SOLV_ERROR_EOF, "unexpected EOF");
       id = 0;
     }
   else
@@ -1047,8 +993,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
            break;
          if (left < 0)
            {
-             pool_debug(pool, SOLV_ERROR, "buffer overrun\n");
-             data.error = SOLV_ERROR_EOF;
+              data.error = pool_error(pool, SOLV_ERROR_EOF, "buffer overrun");
              break;
            }
          if (left < maxsize)
@@ -1062,8 +1007,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags)
                l = allsize;
              if (l && fread(buf + left, l, 1, data.fp) != 1)
                {
-                 pool_debug(pool, SOLV_ERROR, "unexpected EOF\n");
-                 data.error = SOLV_ERROR_EOF;
+                 data.error = pool_error(pool, SOLV_ERROR_EOF, "unexpected EOF");
                  break;
                }
              allsize -= l;
@@ -1173,8 +1117,7 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
            dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data, 0);
          if (idarraydatap > idarraydataend)
            {
-             pool_debug(pool, SOLV_ERROR, "idarray overflow\n");
-             data.error = SOLV_ERROR_OVERFLOW;
+             data.error = pool_error(pool, SOLV_ERROR_OVERFLOW, "idarray overflow");
              break;
            }
          if (id == SOLVABLE_PROVIDES)
@@ -1205,8 +1148,7 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
            needchunk = 1;
           if (keydepth == sizeof(stack)/sizeof(*stack))
            {
-             pool_debug(pool, SOLV_ERROR, "array stack overflow\n");
-             data.error = SOLV_ERROR_CORRUPT;
+             data.error = pool_error(pool, SOLV_ERROR_OVERFLOW, "array stack overflow");
              break;
            }
          stack[keydepth++] = nentries;
@@ -1226,14 +1168,12 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
              /* horray! here come the solvables */
              if (nentries != numsolv)
                {
-                 pool_debug(pool, SOLV_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
-                 data.error = SOLV_ERROR_CORRUPT;
+                 data.error = pool_error(pool, SOLV_ERROR_CORRUPT, "inconsistent number of solvables: %d %d", nentries, numsolv);
                  break;
                }
              if (idarraydatap)
                {
-                 pool_debug(pool, SOLV_ERROR, "more than one solvable block\n");
-                 data.error = SOLV_ERROR_CORRUPT;
+                 data.error = pool_error(pool, SOLV_ERROR_CORRUPT, "more than one solvable block");
                  break;
                }
              if ((flags & REPO_EXTEND_SOLVABLES) != 0)
@@ -1266,10 +1206,7 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
          if (keys[key].type == REPOKEY_TYPE_FIXARRAY)
            {
              if (!id)
-               {
-                 pool_debug(pool, SOLV_ERROR, "illegal fixarray\n");
-                 data.error = SOLV_ERROR_CORRUPT;
-               }
+               data.error = pool_error(pool, SOLV_ERROR_CORRUPT, "illegal fixarray");
              stack[keydepth - 1] = id;
            }
          keyp = schemadata + schemata[id];
@@ -1306,17 +1243,11 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
   /* should shrink idarraydata again */
 
   if (keydepth)
-    {
-      pool_debug(pool, SOLV_ERROR, "unexpected EOF, depth = %d\n", keydepth);
-      data.error = SOLV_ERROR_CORRUPT;
-    }
+    data.error = pool_error(pool, SOLV_ERROR_EOF, "unexpected EOF, depth = %d", keydepth);
   if (!data.error)
     {
       if (dp > bufend)
-        {
-         pool_debug(pool, SOLV_ERROR, "buffer overrun\n");
-         data.error = SOLV_ERROR_EOF;
-        }
+       data.error = pool_error(pool, SOLV_ERROR_EOF, "buffer overrun");
     }
   solv_free(buf);
 
@@ -1357,6 +1288,10 @@ printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, key
       data.lastverticaloffset = fileoffset;
       pagesize = read_u32(&data);
       data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
+      if (data.error == SOLV_ERROR_EOF)
+        pool_error(pool, data.error, "repopagestore setup: unexpected EOF");
+      else if (data.error)
+        pool_error(pool, data.error, "repopagestore setup failed");
     }
   else
     {
index d2e19c6b2912f1fb0f9a85687422a3f0549a61a9..811885cba214bec43421c940832977521475efdd 100644 (file)
@@ -117,7 +117,11 @@ main(int argc, char **argv)
   repo = repo_create(pool, "archpkgs2solv");
   repo_add_repodata(repo, 0);
   for (i = 0; i < npkgs; i++)
-    repo_add_arch_pkg(repo, pkgs[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|flags);
+    if (repo_add_arch_pkg(repo, pkgs[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|flags) != 0)
+      {
+       fprintf(stderr, "archpkgs2solv: %s\n", pool_errstr(pool));
+       exit(1);
+      }
   repo_internalize(repo);
   tool_write(repo, basefile, 0);
   pool_free(pool);
index 3bb7179851e83b8883a97543b3f13de409e9d8ba..6dcb0764f43ce41b0a08d9cbc353db72ad66610a 100644 (file)
@@ -46,7 +46,7 @@ main(int argc, char **argv)
 {
   Pool *pool;
   Repo *repo;
-  int c;
+  int c, ret;
   const char *localdb = 0;
 
   while ((c = getopt(argc, argv, "hl:")) >= 0)
@@ -67,9 +67,14 @@ main(int argc, char **argv)
   pool = pool_create();
   repo = repo_create(pool, "<stdin>");
   if (localdb)
-    repo_add_arch_local(repo, localdb, 0);
+    ret = repo_add_arch_local(repo, localdb, 0);
   else
-    repo_add_arch_repo(repo, stdin, 0);
+    ret = repo_add_arch_repo(repo, stdin, 0);
+  if (ret)
+    {
+      fprintf(stderr, "archrepo2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
index 9dcbe756b0241feb9a2a94fc0a9ed599122e4b80..ba40f355295ab978cf863521b45152754236242c 100644 (file)
@@ -180,7 +180,11 @@ write_info(Repo *repo, FILE *fp, int (*keyfilter)(Repo *repo, Repokey *key, void
   Queue keyq;
 
   queue_init(&keyq);
-  repo_write_filtered(repo, fp, keyfilter, kfdata, &keyq);
+  if (repo_write_filtered(repo, fp, keyfilter, kfdata, &keyq) != 0)
+    {
+      fprintf(stderr, "repo_write failed\n");
+      exit(1);
+    }
   h = repodata_new_handle(info);
   if (keyq.count)
     repodata_set_idarray(info, h, REPOSITORY_KEYS, &keyq);
@@ -298,8 +302,16 @@ tool_write(Repo *repo, const char *basename, const char *attrname)
       kd.languages = languages;
       kd.nlanguages = nlanguages;
       repodata_internalize(info);
-      repo_write_filtered(repo, fp, keyfilter_other, &kd, 0);
-      fclose(fp);
+      if (repo_write_filtered(repo, fp, keyfilter_other, &kd, 0) != 0)
+       {
+         fprintf(stderr, "repo_write failed\n");
+         exit(1);
+       }
+      if (fclose(fp) != 0)
+       {
+         perror("fclose");
+         exit(1);
+       }
       for (i = 0; i < nlanguages; i++)
        free(languages[i]);
       solv_free(languages);
@@ -316,7 +328,11 @@ tool_write(Repo *repo, const char *basename, const char *attrname)
       kd.haveexternal = 1;
     }
   repodata_internalize(info);
-  repo_write_filtered(repo, stdout, keyfilter_solv, &kd, 0);
+  if (repo_write_filtered(repo, stdout, keyfilter_solv, &kd, 0) != 0)
+    {
+      fprintf(stderr, "repo_write failed\n");
+      exit(1);
+    }
   repodata_free(info);
   return 0;
 }
index 1e69e9b161f87b0ce4438b98a6576089528144f7..73854d2e5b882d4bebbd4c4fa719ae690bb5167e 100644 (file)
@@ -31,7 +31,11 @@ main(int argc, char **argv)
 {
   Pool *pool = pool_create();
   Repo *repo = repo_create(pool, "<stdin>");
-  repo_add_comps(repo, stdin, 0);
+  if (repo_add_comps(repo, stdin, 0))
+    {
+      fprintf(stderr, "comps2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
index 1528df2fdffc1af8a6a3912463d3f4345cb5519e..41616bab93836b78943ef8e44ce68c023942f652 100644 (file)
@@ -54,7 +54,11 @@ main(int argc, char **argv)
          break;
        }
     }
-  repo_add_deltainfoxml(repo, stdin, flags);
+  if (repo_add_deltainfoxml(repo, stdin, flags))
+    {
+      fprintf(stderr, "deltainfoxml2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, attrname);
   pool_free(pool);
   exit(0);
index bfc775f30152771839d94ef9400309ac4af7d920..59ac79ad2e450587dfd96aa0d303394668b19219 100644 (file)
@@ -54,7 +54,11 @@ main(int argc, char **argv)
          break;
        }
     }
-  repo_add_diskusagexml(repo, stdin, flags);
+  if (repo_add_diskusagexml(repo, stdin, flags))
+    {
+      fprintf(stderr, "diskusagexml2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, attrname);
   pool_free(pool);
   exit(0);
index 7a648dde13d23ca9d7a5b8cba3f0e2af92cdae9b..11090085fa8a13c516f7483fa66153b0813c7089 100644 (file)
@@ -279,13 +279,13 @@ int main(int argc, char **argv)
        }
       repo = repo_create(pool, argv[optind]);
       if (repo_add_solv(repo, stdin, 0))
-       printf("could not read repository\n");
+       printf("could not read repository: %s\n", pool_errstr(pool));
     }
   if (!pool->urepos)
     {
       repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
       if (repo_add_solv(repo, stdin, 0))
-       printf("could not read repository\n");
+       printf("could not read repository: %s\n", pool_errstr(pool));
     }
   printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
 
index 596438c1b529479b744eecc791d78855d543a5ab..ea64592df92e39582901cd8864b9cbbacc9bb4e7 100644 (file)
@@ -45,7 +45,11 @@ int main(int argc, char **argv)
   pool_setdebuglevel(pool, 1);
   installed = repo_create(pool, "@System");
   pool_set_installed(pool, installed);
-  repo_add_rpmdb(installed, 0, 0, 0);
+  if (repo_add_rpmdb(installed, 0, 0, 0))
+    {
+      fprintf(stderr, "findfileconflicts: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   queue_init(&todo);
   queue_init(&conflicts);
   FOR_REPO_SOLVABLES(installed, p, s)
index a7100f5d5973912427f31a5cac9c7bc7c810e2d7..d893fb122a1fbbdfe150e808b70859b993efb652 100644 (file)
@@ -30,7 +30,11 @@ main(int argc, char **argv)
 {
   Pool *pool = pool_create();
   Repo *repo = repo_create(pool, "<stdin>");
-  repo_add_helix(repo, stdin, 0);
+  if (repo_add_helix(repo, stdin, 0))
+    {
+      fprintf(stderr, "helix2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
index 421c2b151adbc9476a61febb37da29b95dea13a2..4441049dd4a353b6b9b974f51f903f42db7326ea 100644 (file)
@@ -77,7 +77,7 @@ main(int argc, char **argv)
   for (i = 2; i < argc; i++)
     {
       FILE *fp;
-      int l;
+      int r, l;
 
       if (!strcmp(argv[i], "--withsrc"))
        {
@@ -115,38 +115,41 @@ main(int argc, char **argv)
          exit(1);
        }
       repo = repo_create(pool, argv[i]);
+      r = 0;
       if (0)
         {
         }
 #ifdef ENABLE_SUSEREPO
       else if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
        {
-         repo_add_susetags(repo, fp, 0, 0, 0);
+         r = repo_add_susetags(repo, fp, 0, 0, 0);
        }
       else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
        {
-         repo_add_susetags(repo, fp, 0, 0, 0);
+         r = repo_add_susetags(repo, fp, 0, 0, 0);
        }
 #endif
 #ifdef ENABLE_RPMMD
       else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
        {
-         repo_add_rpmmd(repo, fp, 0, 0);
+         r = repo_add_rpmmd(repo, fp, 0, 0);
        }
 #endif
 #ifdef ENABLE_DEBIAN
       else if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
        {
-         repo_add_debpackages(repo, fp, 0);
+         r = repo_add_debpackages(repo, fp, 0);
        }
       else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
        {
-         repo_add_debpackages(repo, fp, 0);
+         r = repo_add_debpackages(repo, fp, 0);
        }
 #endif
-      else if (repo_add_solv(repo, fp, 0))
+      else
+       r = repo_add_solv(repo, fp, 0);
+      if (r)
        {
-         fprintf(stderr, "could not add repo %s\n", argv[i]);
+         fprintf(stderr, "could not add repo %s: %s\n", argv[i], pool_errstr(pool));
          exit(1);
        }
       if (fp != stdin)
index f680f6539a67eb7dd5ce598ffad6018a1aba0a4a..dcf9d6fc04a6fbc9e58b8e90799cc175b9ba8ed8 100644 (file)
@@ -70,7 +70,11 @@ main(int argc, char **argv)
     }
   pool = pool_create();
   repo = repo_create(pool, "<stdin>");
-  repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE);
+  if (repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE))
+    {
+      fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   if (infofile)
     {
       FILE *fp = solv_xfopen(infofile, "r");
@@ -79,7 +83,11 @@ main(int argc, char **argv)
          perror(infofile);
          exit(1);
        }
-      repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+      if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+       {
+         fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
       fclose(fp);
     }
   if (filesfile)
@@ -90,7 +98,11 @@ main(int argc, char **argv)
          perror(filesfile);
          exit(1);
        }
-      repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+      if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+       {
+         fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
       fclose(fp);
     }
   repo_internalize(repo);
index 0d6075c8f4d5553b0525d368c8f7889e45497334..8ff48572b67a4b4635191f7f710c695b2d7830f0 100644 (file)
@@ -94,7 +94,11 @@ main(int argc, char **argv)
          perror(argv[optind]);
          exit(1);
        }
-      repo_add_solv(repo, fp, 0);
+      if (repo_add_solv(repo, fp, 0))
+       {
+         fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool));
+         exit(1);
+       }
       fclose(fp);
     }
   tool_write(repo, basefile, 0);
index b0f4f2cbcc6412e729ba9634c14e68ed1dd04d34..7c91974a6d4b896bb9e779ca27f6cbd5a1db1681 100644 (file)
@@ -486,7 +486,7 @@ main(int argc, char **argv)
 {
   char *arch, *mypatch;
   const char *pname;
-  int l;
+  int l, r;
   FILE *fp;
   int i;
   Id pid, p, pp;
@@ -536,32 +536,35 @@ main(int argc, char **argv)
           perror(argv[i]);
           exit(1);
         }
+      r = 0;
       if (0)
        {
        }
 #ifdef ENABLE_SUSEREPO
       else if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
         {
-          repo_add_susetags(c.repo, fp, 0, 0, 0);
+          r = repo_add_susetags(c.repo, fp, 0, 0, 0);
         }
       else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
         {
-          repo_add_susetags(c.repo, fp, 0, 0, 0);
+          r = repo_add_susetags(c.repo, fp, 0, 0, 0);
         }
 #endif
 #ifdef ENABLE_RPMMD
       else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
         {
-          repo_add_rpmmd(c.repo, fp, 0, 0);
+          r = repo_add_rpmmd(c.repo, fp, 0, 0);
         }
       else if (l >= 17 && !strcmp(argv[i] + l - 17, "updateinfo.xml.gz"))
        {
-          repo_add_updateinfoxml(c.repo, fp, 0);
+          r = repo_add_updateinfoxml(c.repo, fp, 0);
        }
 #endif
-      else if (repo_add_solv(c.repo, fp, 0))
+      else
+       r = repo_add_solv(c.repo, fp, 0);
+      if (r)
         {
-          fprintf(stderr, "could not add repo %s\n", argv[i]);
+          fprintf(stderr, "could not add repo %s: %s\n", argv[i], pool_errstr(pool));
           exit(1);
         }
       if (fp != stdin)
index 9af5e961effd35ff83cccf262084ee3ffd1ad750..58b1d00c56895624590181e6e33e9f68281336c1 100644 (file)
@@ -112,7 +112,11 @@ main(int argc, char **argv)
           break;
         }
     }
-  repo_add_repomdxml(repo, stdin, flags);
+  if (repo_add_repomdxml(repo, stdin, flags))
+    {
+      fprintf(stderr, "repomdxml2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   if (query)
     doquery(pool, repo, query);
   else
index 33796ff464c03b3a465498f8ab3d80127de257b0..e187b13c3153cd3a88d2cd14c3ebab7c0e85a764 100644 (file)
@@ -51,7 +51,6 @@ main(int argc, char **argv)
   Pool *pool = pool_create();
   Repo *repo, *ref = 0;
   Repodata *data;
-  Pool *refpool;
   int c, percent = 0;
   int extrapool = 0;
   int nopacks = 0;
@@ -123,13 +122,19 @@ main(int argc, char **argv)
         }
       else
        {
-         if (extrapool)
-           refpool = pool_create();
+         Pool *refpool = extrapool ? pool_create() : 0;
+         ref = repo_create(refpool ? refpool : pool, "ref");
+         if (repo_add_solv(ref, fp, 0) != 0)
+           {
+             fprintf(stderr, "%s: %s\n", refname, pool_errstr(ref->pool));
+             if (ref->pool != pool)
+               pool_free(ref->pool);
+             else
+               repo_free(ref, 1);
+             ref = 0;
+           }
          else
-           refpool = pool;
-         ref = repo_create(refpool, "ref");
-         repo_add_solv(ref, fp, 0);
-         repo_disable_paging(ref);
+           repo_disable_paging(ref);
          fclose(fp);
        }
     }
@@ -145,7 +150,13 @@ main(int argc, char **argv)
   data = repo_add_repodata(repo, 0);
 
   if (!nopacks)
-    repo_add_rpmdb(repo, ref, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0));
+    {
+      if (repo_add_rpmdb(repo, ref, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
+       {
+         fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
+    }
 
 #ifdef ENABLE_SUSEREPO
   if (proddir && *proddir)
@@ -164,7 +175,11 @@ main(int argc, char **argv)
              strcpy(buf + rootlen, proddir);
            }
        }
-      repo_add_products(repo, buf, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+      if (repo_add_products(repo, buf, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+       {
+         fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
       if (buf != proddir)
        solv_free(buf);
     }
index b1f9e3e75dabb9f5645fd1089592d9f50cc6f3b1..ee39eac930d549e61974b61c71317ed2e32f0653 100644 (file)
@@ -85,12 +85,20 @@ main(int argc, char **argv)
          perror(fnp);
          exit(1);
        }
-      repo_add_rpmmd(repo, fp, 0, flags);
+      if (repo_add_rpmmd(repo, fp, 0, flags))
+       {
+         fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+         exit(1);
+       }
       fclose(fp);
       snprintf(fnp, l, "%s/diskusagedata.xml.gz", dir);
       if ((fp = solv_xfopen(fnp, 0)))
        {
-         repo_add_rpmmd(repo, fp, 0, flags);
+         if (repo_add_rpmmd(repo, fp, 0, flags))
+           {
+             fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+             exit(1);
+           }
          fclose(fp);
        }
       if (locale)
@@ -117,13 +125,23 @@ main(int argc, char **argv)
              exit(1);
            }
          fprintf(stderr, "opened %s\n", fnp);
-         repo_add_rpmmd(repo, fp, 0, flags);
+         if (repo_add_rpmmd(repo, fp, 0, flags))
+           {
+             fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+             exit(1);
+           }
          fclose(fp);
        }
       solv_free(fnp);
     }
   else
-    repo_add_rpmmd(repo, stdin, 0, flags);
+    {
+      if (repo_add_rpmmd(repo, stdin, 0, flags))
+       {
+         fprintf(stderr, "rpmmd2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
+    }
   tool_write(repo, basefile, attrname);
   pool_free(pool);
   exit(0);
index b1daec6f5ab24f3d6d35bf3689030563b8332601..79a36845aa3a799a70a9846eda0ba543d6c29cbe 100644 (file)
@@ -111,7 +111,11 @@ main(int argc, char **argv)
       rpms[nrpms++] = strdup(argv[optind++]);
     }
   repo = repo_create(pool, "rpms2solv");
-  repo_add_rpms(repo, rpms, nrpms, 0);
+  if (repo_add_rpms(repo, rpms, nrpms, 0))
+    {
+      fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, basefile, 0);
   pool_free(pool);
   for (c = 0; c < nrpms; c++)
index 93447919082bae166f1e4918d9ecd073d6ba3faf..f94e517ba682df2701864bcf3e0e0fd6dcbccbff 100644 (file)
@@ -110,7 +110,11 @@ main(int argc, char **argv)
          perror(contentfile);
          exit(1);
        }
-      repo_add_content(repo, fp, REPO_REUSE_REPODATA);
+      if (repo_add_content(repo, fp, REPO_REUSE_REPODATA))
+       {
+         fprintf(stderr, "susetags2solv: %s: %s\n", contentfile, pool_errstr(pool));
+         exit(1);
+       }
       defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
       fclose(fp);
     }
@@ -180,7 +184,11 @@ main(int argc, char **argv)
                  perror(fn);
                  exit(1);
                }
-             repo_add_susetags(repo, fp, defvendor, 0, flags | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+             if (repo_add_susetags(repo, fp, defvendor, 0, flags | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+               {
+                 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
+                 exit(1);
+               }
              fclose(fp);
            }
          else if (!strcmp(fn, "packages.DU") || !strcmp(fn, "packages.DU.gz"))
@@ -193,7 +201,11 @@ main(int argc, char **argv)
                  perror(fn);
                  exit(1);
                }
-             repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+             if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+               {
+                 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
+                 exit(1);
+               }
              fclose(fp);
            }
          else if (!strcmp(fn, "packages.FL") || !strcmp(fn, "packages.FL.gz"))
@@ -206,7 +218,11 @@ main(int argc, char **argv)
                  perror(fn);
                  exit(1);
                }
-             repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+             if (repo_add_susetags(repo, fp, defvendor, 0, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+               {
+                 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
+                 exit(1);
+               }
              fclose(fp);
 #else
              /* ignore for now. reactivate when filters work */
@@ -235,7 +251,11 @@ main(int argc, char **argv)
                  perror(fn);
                  exit(1);
                }
-             repo_add_susetags(repo, fp, defvendor, lang, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+             if (repo_add_susetags(repo, fp, defvendor, lang, flags | SUSETAGS_EXTEND | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+               {
+                 fprintf(stderr, "susetags2solv: %s: %s\n", fnp, pool_errstr(pool));
+                 exit(1);
+               }
              fclose(fp);
            }
        }
@@ -246,8 +266,14 @@ main(int argc, char **argv)
       repo_internalize(repo);
     }
   else
-    /* read data from stdin */
-    repo_add_susetags(repo, stdin, defvendor, 0, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
+    {
+      /* read data from stdin */
+      if (repo_add_susetags(repo, stdin, defvendor, 0, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+       {
+         fprintf(stderr, "susetags2solv: %s\n", pool_errstr(pool));
+         exit(1);
+       }
+    }
   repo_internalize(repo);
 
   if (query)
index 921538fb6c41907a84967664bf431765618136b5..5432150025b55ebea3249257d59b298fc4d06f1b 100644 (file)
@@ -54,7 +54,11 @@ main(int argc, char **argv)
          break;
        }
     }
-  repo_add_updateinfoxml(repo, stdin, flags);
+  if (repo_add_updateinfoxml(repo, stdin, flags))
+    {
+      fprintf(stderr, "updateinfoxml2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
   tool_write(repo, 0, attrname);
   pool_free(pool);
   exit(0);