diff options
-rw-r--r-- | examples/solv.c | 94 | ||||
-rw-r--r-- | ext/repo_deb.c | 6 | ||||
-rw-r--r-- | ext/repo_deltainfoxml.c | 13 | ||||
-rw-r--r-- | ext/repo_helix.c | 7 | ||||
-rw-r--r-- | ext/repo_repomdxml.c | 22 | ||||
-rw-r--r-- | ext/repo_rpmdb.c | 117 | ||||
-rw-r--r-- | ext/repo_rpmmd.c | 46 | ||||
-rw-r--r-- | ext/repo_susetags.c | 56 | ||||
-rw-r--r-- | ext/repo_updateinfoxml.c | 8 | ||||
-rw-r--r-- | src/libsolv.ver | 2 | ||||
-rw-r--r-- | src/pool.c | 44 | ||||
-rw-r--r-- | src/pool.h | 6 | ||||
-rw-r--r-- | src/repo_solv.c | 155 | ||||
-rw-r--r-- | tools/archpkgs2solv.c | 6 | ||||
-rw-r--r-- | tools/archrepo2solv.c | 11 | ||||
-rw-r--r-- | tools/common_write.c | 24 | ||||
-rw-r--r-- | tools/comps2solv.c | 6 | ||||
-rw-r--r-- | tools/deltainfoxml2solv.c | 6 | ||||
-rw-r--r-- | tools/diskusagexml2solv.c | 6 | ||||
-rw-r--r-- | tools/dumpsolv.c | 4 | ||||
-rw-r--r-- | tools/findfileconflicts.c | 6 | ||||
-rw-r--r-- | tools/helix2solv.c | 6 | ||||
-rw-r--r-- | tools/installcheck.c | 19 | ||||
-rw-r--r-- | tools/mdk2solv.c | 18 | ||||
-rw-r--r-- | tools/mergesolv.c | 6 | ||||
-rw-r--r-- | tools/patchcheck.c | 17 | ||||
-rw-r--r-- | tools/repomdxml2solv.c | 6 | ||||
-rw-r--r-- | tools/rpmdb2solv.c | 33 | ||||
-rw-r--r-- | tools/rpmmd2solv.c | 26 | ||||
-rw-r--r-- | tools/rpms2solv.c | 6 | ||||
-rw-r--r-- | tools/susetags2solv.c | 40 | ||||
-rw-r--r-- | tools/updateinfoxml2solv.c | 6 |
32 files changed, 529 insertions, 299 deletions
diff --git a/examples/solv.c b/examples/solv.c index d19939f..f14d37f 100644 --- a/examples/solv.c +++ b/examples/solv.c @@ -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); diff --git a/ext/repo_deb.c b/ext/repo_deb.c index 38327c6..7e967a7 100644 --- a/ext/repo_deb.c +++ b/ext/repo_deb.c @@ -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; diff --git a/ext/repo_deltainfoxml.c b/ext/repo_deltainfoxml.c index 5e6e86e..c841f5e 100644 --- a/ext/repo_deltainfoxml.c +++ b/ext/repo_deltainfoxml.c @@ -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 */ diff --git a/ext/repo_helix.c b/ext/repo_helix.c index 8e74efa..7415b29 100644 --- a/ext/repo_helix.c +++ b/ext/repo_helix.c @@ -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; } diff --git a/ext/repo_repomdxml.c b/ext/repo_repomdxml.c index faa8456..0697aa8 100644 --- a/ext/repo_repomdxml.c +++ b/ext/repo_repomdxml.c @@ -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 */ diff --git a/ext/repo_rpmdb.c b/ext/repo_rpmdb.c index 1c68139..c66c6f0 100644 --- a/ext/repo_rpmdb.c +++ b/ext/repo_rpmdb.c @@ -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); diff --git a/ext/repo_rpmmd.c b/ext/repo_rpmmd.c index efde4fd..80e54c6 100644 --- a/ext/repo_rpmmd.c +++ b/ext/repo_rpmmd.c @@ -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; } diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index 501916e..5ed8d9f 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -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; } diff --git a/ext/repo_updateinfoxml.c b/ext/repo_updateinfoxml.c index dc8f392..59e9b17 100644 --- a/ext/repo_updateinfoxml.c +++ b/ext/repo_updateinfoxml.c @@ -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; } diff --git a/src/libsolv.ver b/src/libsolv.ver index 78f6d35..a2e100c 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -54,6 +54,8 @@ SOLV_1.0 { pool_createwhatprovides; pool_debug; pool_dep2str; + pool_error; + pool_errstr; pool_evrcmp; pool_evrcmp_str; pool_evrmatch; @@ -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) @@ -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 */ diff --git a/src/repo_solv.c b/src/repo_solv.c index 3f391ef..84e4835 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -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 { diff --git a/tools/archpkgs2solv.c b/tools/archpkgs2solv.c index d2e19c6..811885c 100644 --- a/tools/archpkgs2solv.c +++ b/tools/archpkgs2solv.c @@ -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); diff --git a/tools/archrepo2solv.c b/tools/archrepo2solv.c index 3bb7179..6dcb076 100644 --- a/tools/archrepo2solv.c +++ b/tools/archrepo2solv.c @@ -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); diff --git a/tools/common_write.c b/tools/common_write.c index 9dcbe75..ba40f35 100644 --- a/tools/common_write.c +++ b/tools/common_write.c @@ -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; } diff --git a/tools/comps2solv.c b/tools/comps2solv.c index 1e69e9b..73854d2 100644 --- a/tools/comps2solv.c +++ b/tools/comps2solv.c @@ -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); diff --git a/tools/deltainfoxml2solv.c b/tools/deltainfoxml2solv.c index 1528df2..41616ba 100644 --- a/tools/deltainfoxml2solv.c +++ b/tools/deltainfoxml2solv.c @@ -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); diff --git a/tools/diskusagexml2solv.c b/tools/diskusagexml2solv.c index bfc775f..59ac79a 100644 --- a/tools/diskusagexml2solv.c +++ b/tools/diskusagexml2solv.c @@ -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); diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index 7a648dd..1109008 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -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); diff --git a/tools/findfileconflicts.c b/tools/findfileconflicts.c index 596438c..ea64592 100644 --- a/tools/findfileconflicts.c +++ b/tools/findfileconflicts.c @@ -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) diff --git a/tools/helix2solv.c b/tools/helix2solv.c index a7100f5..d893fb1 100644 --- a/tools/helix2solv.c +++ b/tools/helix2solv.c @@ -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); diff --git a/tools/installcheck.c b/tools/installcheck.c index 421c2b1..4441049 100644 --- a/tools/installcheck.c +++ b/tools/installcheck.c @@ -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) diff --git a/tools/mdk2solv.c b/tools/mdk2solv.c index f680f65..dcf9d6f 100644 --- a/tools/mdk2solv.c +++ b/tools/mdk2solv.c @@ -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); diff --git a/tools/mergesolv.c b/tools/mergesolv.c index 0d6075c..8ff4857 100644 --- a/tools/mergesolv.c +++ b/tools/mergesolv.c @@ -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); diff --git a/tools/patchcheck.c b/tools/patchcheck.c index b0f4f2c..7c91974 100644 --- a/tools/patchcheck.c +++ b/tools/patchcheck.c @@ -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) diff --git a/tools/repomdxml2solv.c b/tools/repomdxml2solv.c index 9af5e96..58b1d00 100644 --- a/tools/repomdxml2solv.c +++ b/tools/repomdxml2solv.c @@ -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 diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index 33796ff..e187b13 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -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); } diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index b1f9e3e..ee39eac 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -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); diff --git a/tools/rpms2solv.c b/tools/rpms2solv.c index b1daec6..79a3684 100644 --- a/tools/rpms2solv.c +++ b/tools/rpms2solv.c @@ -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++) diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index 9344791..f94e517 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -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) diff --git a/tools/updateinfoxml2solv.c b/tools/updateinfoxml2solv.c index 921538f..5432150 100644 --- a/tools/updateinfoxml2solv.c +++ b/tools/updateinfoxml2solv.c @@ -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); |