summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2012-04-16 17:57:18 +0200
committerMichael Schroeder <mls@suse.de>2012-04-16 18:12:57 +0200
commit64af5496c8e755df389d568c8e5c1045dcda9483 (patch)
tree75d23814ad92176fae8d0b186be0beaf946282b1
parent8cf2c0ad50a294ea14538b87cb7f34ea540c36f5 (diff)
downloadlibsolv-64af5496c8e755df389d568c8e5c1045dcda9483.tar.gz
libsolv-64af5496c8e755df389d568c8e5c1045dcda9483.tar.bz2
libsolv-64af5496c8e755df389d568c8e5c1045dcda9483.zip
- get rid of plural forms of repo_add_pkg, use pool_error instead printing to stderr
-rw-r--r--ext/libsolvext.ver4
-rw-r--r--ext/repo_content.c9
-rw-r--r--ext/repo_deb.c299
-rw-r--r--ext/repo_deb.h1
-rw-r--r--ext/repo_rpmdb.c373
-rw-r--r--ext/repo_rpmdb.h3
-rw-r--r--tools/archpkgs2solv.c7
-rw-r--r--tools/common_write.c4
-rw-r--r--tools/common_write.h2
-rw-r--r--tools/rpms2solv.c17
10 files changed, 354 insertions, 365 deletions
diff --git a/ext/libsolvext.ver b/ext/libsolvext.ver
index 7c830aa..7796925 100644
--- a/ext/libsolvext.ver
+++ b/ext/libsolvext.ver
@@ -10,20 +10,18 @@ SOLV_1.0 {
repo_add_deb;
repo_add_debdb;
repo_add_debpackages;
- repo_add_debs;
repo_add_deltainfoxml;
repo_add_helix;
repo_add_mdk;
repo_add_mdk_info;
repo_add_products;
- repo_add_pubkeys;
+ repo_add_pubkey;
repo_add_releasefile_products;
repo_add_repomdxml;
repo_add_rpm;
repo_add_rpmdb;
repo_add_rpmdb_pubkeys;
repo_add_rpmmd;
- repo_add_rpms;
repo_add_susetags;
repo_add_updateinfoxml;
repo_add_zyppdb_products;
diff --git a/ext/repo_content.c b/ext/repo_content.c
index a51f7c2..75f339c 100644
--- a/ext/repo_content.c
+++ b/ext/repo_content.c
@@ -213,6 +213,7 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
char *defvendor = 0;
int i = 0;
+ int res = 0;
/* architectures
we use the first architecture in BASEARCHS or noarch
@@ -339,13 +340,15 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
type = solv_chksum_str2type(checksumtype);
if (!type)
{
- fprintf(stderr, "Unknown checksum type: %s: %s\n", value, checksumtype);
+ pool_error(pool, -1, "%s: unknown checksum type '%s'", value, checksumtype);
+ res = 1;
continue;
}
l = solv_chksum_len(type);
if (strlen(checksum) != 2 * l)
{
- fprintf(stderr, "Invalid checksum length: %s: for %s\n", value, checksum);
+ pool_error(pool, -1, "%s: invalid checksum length for %s", value, checksumtype);
+ res = 1;
continue;
}
fh = repodata_new_handle(data);
@@ -545,5 +548,5 @@ repo_add_content(Repo *repo, FILE *fp, int flags)
solv_free(otherarchs);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- return 0;
+ return res;
}
diff --git a/ext/repo_deb.c b/ext/repo_deb.c
index 7e967a7..635a987 100644
--- a/ext/repo_deb.c
+++ b/ext/repo_deb.c
@@ -427,13 +427,13 @@ repo_add_debdb(Repo *repo, const char *rootdir, int flags)
return 0;
}
-int
-repo_add_debs(Repo *repo, const char **debs, int ndebs, int flags)
+Id
+repo_add_deb(Repo *repo, const char *deb, int flags)
{
Pool *pool = repo->pool;
Repodata *data;
unsigned char buf[4096], *bp;
- int i, l, l2, vlen, clen, ctarlen;
+ int l, l2, vlen, clen, ctarlen;
unsigned char *ctgz;
unsigned char pkgid[16];
unsigned char *ctar;
@@ -443,170 +443,157 @@ repo_add_debs(Repo *repo, const char **debs, int ndebs, int flags)
struct stat stb;
data = repo_add_repodata(repo, flags);
- for (i = 0; i < ndebs; i++)
+ if ((fp = fopen(deb, "r")) == 0)
{
- if ((fp = fopen(debs[i], "r")) == 0)
- {
- perror(debs[i]);
- continue;
- }
- if (fstat(fileno(fp), &stb))
- {
- perror("stat");
- continue;
- }
- l = fread(buf, 1, sizeof(buf), fp);
- if (l < 8 + 60 || strncmp((char *)buf, "!<arch>\ndebian-binary ", 8 + 16) != 0)
- {
- fprintf(stderr, "%s: not a deb package\n", debs[i]);
- fclose(fp);
- continue;
- }
- vlen = atoi((char *)buf + 8 + 48);
- if (vlen < 0 || vlen > l)
- {
- fprintf(stderr, "%s: not a deb package\n", debs[i]);
- fclose(fp);
- continue;
- }
- vlen += vlen & 1;
- if (l < 8 + 60 + vlen + 60)
- {
- fprintf(stderr, "%s: unhandled deb package\n", debs[i]);
- fclose(fp);
- continue;
- }
- if (strncmp((char *)buf + 8 + 60 + vlen, "control.tar.gz ", 16) != 0)
- {
- fprintf(stderr, "%s: control.tar.gz is not second entry\n", debs[i]);
- fclose(fp);
- continue;
- }
- clen = atoi((char *)buf + 8 + 60 + vlen + 48);
- if (clen <= 0)
- {
- fprintf(stderr, "%s: control.tar.gz has illegal size\n", debs[i]);
- fclose(fp);
- continue;
- }
- ctgz = solv_calloc(1, clen + 4);
- bp = buf + 8 + 60 + vlen + 60;
- l -= 8 + 60 + vlen + 60;
- if (l > clen)
- l = clen;
- if (l)
- memcpy(ctgz, bp, l);
- if (l < clen)
- {
- if (fread(ctgz + l, clen - l, 1, fp) != 1)
- {
- fprintf(stderr, "%s: unexpected EOF\n", debs[i]);
- solv_free(ctgz);
- fclose(fp);
- continue;
- }
- }
+ pool_error(pool, -1, "%s: %s", deb, strerror(errno));
+ return 0;
+ }
+ if (fstat(fileno(fp), &stb))
+ {
+ pool_error(pool, -1, "fstat: %s", strerror(errno));
fclose(fp);
- gotpkgid = 0;
- if (flags & DEBS_ADD_WITH_PKGID)
- {
- void *handle = solv_chksum_create(REPOKEY_TYPE_MD5);
- solv_chksum_add(handle, ctgz, clen);
- solv_chksum_free(handle, pkgid);
- gotpkgid = 1;
- }
- if (ctgz[0] != 0x1f || ctgz[1] != 0x8b)
- {
- fprintf(stderr, "%s: control.tar.gz is not gzipped\n", debs[i]);
- solv_free(ctgz);
- continue;
- }
- if (ctgz[2] != 8 || (ctgz[3] & 0xe0) != 0)
+ return 0;
+ }
+ l = fread(buf, 1, sizeof(buf), fp);
+ if (l < 8 + 60 || strncmp((char *)buf, "!<arch>\ndebian-binary ", 8 + 16) != 0)
+ {
+ pool_error(pool, -1, "%s: not a deb package", deb);
+ fclose(fp);
+ return 0;
+ }
+ vlen = atoi((char *)buf + 8 + 48);
+ if (vlen < 0 || vlen > l)
+ {
+ pool_error(pool, -1, "%s: not a deb package", deb);
+ fclose(fp);
+ return 0;
+ }
+ vlen += vlen & 1;
+ if (l < 8 + 60 + vlen + 60)
+ {
+ pool_error(pool, -1, "%s: unhandled deb package", deb);
+ fclose(fp);
+ return 0;
+ }
+ if (strncmp((char *)buf + 8 + 60 + vlen, "control.tar.gz ", 16) != 0)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz is not second entry", deb);
+ fclose(fp);
+ return 0;
+ }
+ clen = atoi((char *)buf + 8 + 60 + vlen + 48);
+ if (clen <= 0 || clen >= 0x100000)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz has illegal size", deb);
+ fclose(fp);
+ return 0;
+ }
+ ctgz = solv_calloc(1, clen + 4);
+ bp = buf + 8 + 60 + vlen + 60;
+ l -= 8 + 60 + vlen + 60;
+ if (l > clen)
+ l = clen;
+ if (l)
+ memcpy(ctgz, bp, l);
+ if (l < clen)
+ {
+ if (fread(ctgz + l, clen - l, 1, fp) != 1)
{
- fprintf(stderr, "%s: control.tar.gz is compressed in a strange way\n", debs[i]);
+ pool_error(pool, -1, "%s: unexpected EOF", deb);
solv_free(ctgz);
- continue;
- }
- bp = ctgz + 4;
- bp += 6; /* skip time, xflags and OS code */
- if (ctgz[3] & 0x04)
- {
- /* skip extra field */
- l = bp[0] | bp[1] << 8;
- bp += l + 2;
- if (bp >= ctgz + clen)
- {
- fprintf(stderr, "%s: corrupt gzip\n", debs[i]);
- solv_free(ctgz);
- continue;
- }
+ fclose(fp);
+ return 0;
}
- if (ctgz[3] & 0x08) /* orig filename */
- while (*bp)
- bp++;
- if (ctgz[3] & 0x10) /* file comment */
- while (*bp)
- bp++;
- if (ctgz[3] & 0x02) /* header crc */
- bp += 2;
+ }
+ fclose(fp);
+ gotpkgid = 0;
+ if (flags & DEBS_ADD_WITH_PKGID)
+ {
+ void *handle = solv_chksum_create(REPOKEY_TYPE_MD5);
+ solv_chksum_add(handle, ctgz, clen);
+ solv_chksum_free(handle, pkgid);
+ gotpkgid = 1;
+ }
+ if (ctgz[0] != 0x1f || ctgz[1] != 0x8b)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz is not gzipped", deb);
+ solv_free(ctgz);
+ return 0;
+ }
+ if (ctgz[2] != 8 || (ctgz[3] & 0xe0) != 0)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz is compressed in a strange way", deb);
+ solv_free(ctgz);
+ return 0;
+ }
+ bp = ctgz + 4;
+ bp += 6; /* skip time, xflags and OS code */
+ if (ctgz[3] & 0x04)
+ {
+ /* skip extra field */
+ l = bp[0] | bp[1] << 8;
+ bp += l + 2;
if (bp >= ctgz + clen)
{
- fprintf(stderr, "%s: corrupt control.tar.gz\n", debs[i]);
+ pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
solv_free(ctgz);
- continue;
+ return 0;
}
- ctar = decompress(bp, ctgz + clen - bp, &ctarlen);
+ }
+ if (ctgz[3] & 0x08) /* orig filename */
+ while (*bp)
+ bp++;
+ if (ctgz[3] & 0x10) /* file comment */
+ while (*bp)
+ bp++;
+ if (ctgz[3] & 0x02) /* header crc */
+ bp += 2;
+ if (bp >= ctgz + clen)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
solv_free(ctgz);
- if (!ctar)
- {
- fprintf(stderr, "%s: corrupt control.tar.gz\n", debs[i]);
- continue;
- }
- bp = ctar;
- l = ctarlen;
- while (l > 512)
- {
- int j;
- l2 = 0;
- for (j = 124; j < 124 + 12; j++)
- if (bp[j] >= '0' && bp[j] <= '7')
- l2 = l2 * 8 + (bp[j] - '0');
- if (!strcmp((char *)bp, "./control") || !strcmp((char *)bp, "control"))
- break;
- l2 = 512 + ((l2 + 511) & ~511);
- l -= l2;
- bp += l2;
- }
- if (l <= 512 || l - 512 - l2 <= 0 || l2 <= 0)
- {
- fprintf(stderr, "%s: control.tar.gz contains no control file\n", debs[i]);
- free(ctar);
- continue;
- }
- memmove(ctar, bp + 512, l2);
- ctar = solv_realloc(ctar, l2 + 1);
- ctar[l2] = 0;
- s = pool_id2solvable(pool, repo_add_solvable(repo));
- control2solvable(s, data, (char *)ctar);
- repodata_set_location(data, s - pool->solvables, 0, 0, debs[i]);
- if (S_ISREG(stb.st_mode))
- repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
- if (gotpkgid)
- repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
- solv_free(ctar);
+ return 0;
+ }
+ ctar = decompress(bp, ctgz + clen - bp, &ctarlen);
+ solv_free(ctgz);
+ if (!ctar)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz is corrupt", deb);
+ return 0;
}
+ bp = ctar;
+ l = ctarlen;
+ while (l > 512)
+ {
+ int j;
+ l2 = 0;
+ for (j = 124; j < 124 + 12; j++)
+ if (bp[j] >= '0' && bp[j] <= '7')
+ l2 = l2 * 8 + (bp[j] - '0');
+ if (!strcmp((char *)bp, "./control") || !strcmp((char *)bp, "control"))
+ break;
+ l2 = 512 + ((l2 + 511) & ~511);
+ l -= l2;
+ bp += l2;
+ }
+ if (l <= 512 || l - 512 - l2 <= 0 || l2 <= 0)
+ {
+ pool_error(pool, -1, "%s: control.tar.gz contains no control file", deb);
+ free(ctar);
+ return 0;
+ }
+ memmove(ctar, bp + 512, l2);
+ ctar = solv_realloc(ctar, l2 + 1);
+ ctar[l2] = 0;
+ s = pool_id2solvable(pool, repo_add_solvable(repo));
+ control2solvable(s, data, (char *)ctar);
+ repodata_set_location(data, s - pool->solvables, 0, 0, deb);
+ if (S_ISREG(stb.st_mode))
+ repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
+ if (gotpkgid)
+ repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
+ solv_free(ctar);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- return 0;
-}
-
-Id
-repo_add_deb(Repo *repo, const char *deb, int flags)
-{
- int end = repo->end;
- repo_add_debs(repo, &deb, 1, flags);
- if (end == repo->end)
- return 0;
- else
- return repo->end - 1;
+ return s - pool->solvables;
}
diff --git a/ext/repo_deb.h b/ext/repo_deb.h
index 4d3e019..3ca3fdf 100644
--- a/ext/repo_deb.h
+++ b/ext/repo_deb.h
@@ -7,7 +7,6 @@
extern int repo_add_debpackages(Repo *repo, FILE *fp, int flags);
extern int repo_add_debdb(Repo *repo, const char *rootdir, int flags);
-extern int repo_add_debs(Repo *repo, const char **debs, int ndebs, int flags);
extern Id repo_add_deb(Repo *repo, const char *deb, int flags);
#define DEBS_ADD_WITH_PKGID (1 << 8)
diff --git a/ext/repo_rpmdb.c b/ext/repo_rpmdb.c
index c66c6f0..23b5508 100644
--- a/ext/repo_rpmdb.c
+++ b/ext/repo_rpmdb.c
@@ -1803,10 +1803,10 @@ getu32(const unsigned char *dp)
}
-int
-repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags)
+Id
+repo_add_rpm(Repo *repo, const char *rpm, int flags)
{
- int i, sigdsize, sigcnt, l;
+ int sigdsize, sigcnt, l;
Pool *pool = repo->pool;
Solvable *s;
RpmHead *rpmhead = 0;
@@ -1828,189 +1828,178 @@ repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags)
chksumtype = REPOKEY_TYPE_SHA256;
else if ((flags & RPM_ADD_WITH_SHA1SUM) != 0)
chksumtype = REPOKEY_TYPE_SHA1;
- for (i = 0; i < nrpms; i++)
+
+ if ((fp = fopen(rpm, "r")) == 0)
{
- if ((fp = fopen(rpms[i], "r")) == 0)
- {
- perror(rpms[i]);
- continue;
- }
- if (fstat(fileno(fp), &stb))
+ pool_error(pool, -1, "%s: %s", rpm, strerror(errno));
+ return 0;
+ }
+ if (fstat(fileno(fp), &stb))
+ {
+ pool_error(pool, -1, "fstat: %s", strerror(errno));
+ fclose(fp);
+ return 0;
+ }
+ if (chksumtype)
+ chksumh = solv_chksum_create(chksumtype);
+ if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
+ {
+ pool_error(pool, -1, "%s: not a rpm", rpm);
+ fclose(fp);
+ return 0;
+ }
+ if (chksumh)
+ solv_chksum_add(chksumh, lead, 96 + 16);
+ if (lead[78] != 0 || lead[79] != 5)
+ {
+ pool_error(pool, -1, "%s: not a rpm v5 header", rpm);
+ fclose(fp);
+ return 0;
+ }
+ if (getu32(lead + 96) != 0x8eade801)
+ {
+ pool_error(pool, -1, "%s: bad signature header", rpm);
+ fclose(fp);
+ return 0;
+ }
+ sigcnt = getu32(lead + 96 + 8);
+ sigdsize = getu32(lead + 96 + 12);
+ if (sigcnt >= 0x100000 || sigdsize >= 0x100000)
+ {
+ pool_error(pool, -1, "%s: bad signature header", rpm);
+ fclose(fp);
+ return 0;
+ }
+ sigdsize += sigcnt * 16;
+ sigdsize = (sigdsize + 7) & ~7;
+ headerstart = 96 + 16 + sigdsize;
+ gotpkgid = 0;
+ if ((flags & RPM_ADD_WITH_PKGID) != 0)
+ {
+ unsigned char *chksum;
+ unsigned int chksumsize;
+ /* extract pkgid from the signature header */
+ if (sigdsize > rpmheadsize)
{
- perror("stat");
- continue;
+ rpmheadsize = sigdsize + 128;
+ rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
}
- if (chksumh)
- chksumh = solv_chksum_free(chksumh, 0);
- if (chksumtype)
- chksumh = solv_chksum_create(chksumtype);
- if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
+ if (fread(rpmhead->data, sigdsize, 1, fp) != 1)
{
- fprintf(stderr, "%s: not a rpm\n", rpms[i]);
+ pool_error(pool, -1, "%s: unexpected EOF", rpm);
fclose(fp);
- continue;
+ return 0;
}
if (chksumh)
- solv_chksum_add(chksumh, lead, 96 + 16);
- if (lead[78] != 0 || lead[79] != 5)
- {
- fprintf(stderr, "%s: not a V5 header\n", rpms[i]);
- fclose(fp);
- continue;
- }
- if (getu32(lead + 96) != 0x8eade801)
- {
- fprintf(stderr, "%s: bad signature header\n", rpms[i]);
- fclose(fp);
- continue;
- }
- sigcnt = getu32(lead + 96 + 8);
- sigdsize = getu32(lead + 96 + 12);
- if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
+ solv_chksum_add(chksumh, rpmhead->data, sigdsize);
+ rpmhead->cnt = sigcnt;
+ rpmhead->dcnt = sigdsize - sigcnt * 16;
+ rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
+ chksum = headbinary(rpmhead, SIGTAG_MD5, &chksumsize);
+ if (chksum && chksumsize == 16)
{
- fprintf(stderr, "%s: bad signature header\n", rpms[i]);
- fclose(fp);
- continue;
+ gotpkgid = 1;
+ memcpy(pkgid, chksum, 16);
}
- sigdsize += sigcnt * 16;
- sigdsize = (sigdsize + 7) & ~7;
- headerstart = 96 + 16 + sigdsize;
- gotpkgid = 0;
- if ((flags & RPM_ADD_WITH_PKGID) != 0)
+ }
+ else
+ {
+ /* just skip the signature header */
+ while (sigdsize)
{
- unsigned char *chksum;
- unsigned int chksumsize;
- /* extract pkgid from the signature header */
- if (sigdsize > rpmheadsize)
- {
- rpmheadsize = sigdsize + 128;
- rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
- }
- if (fread(rpmhead->data, sigdsize, 1, fp) != 1)
+ l = sigdsize > 4096 ? 4096 : sigdsize;
+ if (fread(lead, l, 1, fp) != 1)
{
- fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
+ pool_error(pool, -1, "%s: unexpected EOF", rpm);
fclose(fp);
- continue;
+ return 0;
}
if (chksumh)
- solv_chksum_add(chksumh, rpmhead->data, sigdsize);
- rpmhead->cnt = sigcnt;
- rpmhead->dcnt = sigdsize - sigcnt * 16;
- rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
- chksum = headbinary(rpmhead, SIGTAG_MD5, &chksumsize);
- if (chksum && chksumsize == 16)
- {
- gotpkgid = 1;
- memcpy(pkgid, chksum, 16);
- }
+ solv_chksum_add(chksumh, lead, l);
+ sigdsize -= l;
}
- else
- {
- /* just skip the signature header */
- while (sigdsize)
- {
- l = sigdsize > 4096 ? 4096 : sigdsize;
- if (fread(lead, l, 1, fp) != 1)
- {
- fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
- fclose(fp);
- continue;
- }
- if (chksumh)
- solv_chksum_add(chksumh, lead, l);
- sigdsize -= l;
- }
- }
- if (fread(lead, 16, 1, fp) != 1)
- {
- fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
- fclose(fp);
- continue;
- }
- if (chksumh)
- solv_chksum_add(chksumh, lead, 16);
- if (getu32(lead) != 0x8eade801)
- {
- fprintf(stderr, "%s: bad header\n", rpms[i]);
- fclose(fp);
- continue;
- }
- sigcnt = getu32(lead + 8);
- sigdsize = getu32(lead + 12);
- if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
- {
- fprintf(stderr, "%s: bad header\n", rpms[i]);
- fclose(fp);
- continue;
- }
- l = sigdsize + sigcnt * 16;
- headerend = headerstart + 16 + l;
- if (l > rpmheadsize)
- {
- rpmheadsize = l + 128;
- rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
- }
- if (fread(rpmhead->data, l, 1, fp) != 1)
- {
- fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
- fclose(fp);
- continue;
- }
- if (chksumh)
- solv_chksum_add(chksumh, rpmhead->data, l);
- rpmhead->cnt = sigcnt;
- rpmhead->dcnt = sigdsize;
- rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
- if (headexists(rpmhead, TAG_PATCHESNAME))
- {
- /* this is a patch rpm, ignore */
- fclose(fp);
- continue;
- }
- payloadformat = headstring(rpmhead, TAG_PAYLOADFORMAT);
- if (payloadformat && !strcmp(payloadformat, "drpm"))
- {
- /* this is a delta rpm */
- fclose(fp);
- continue;
- }
- if (chksumh)
- while ((l = fread(lead, 1, sizeof(lead), fp)) > 0)
- solv_chksum_add(chksumh, lead, l);
+ }
+ if (fread(lead, 16, 1, fp) != 1)
+ {
+ pool_error(pool, -1, "%s: unexpected EOF", rpm);
fclose(fp);
- s = pool_id2solvable(pool, repo_add_solvable(repo));
- rpm2solv(pool, repo, data, s, rpmhead, flags);
- if (data)
- {
- Id handle = s - pool->solvables;
- repodata_set_location(data, handle, 0, 0, rpms[i]);
- if (S_ISREG(stb.st_mode))
- repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
- repodata_set_num(data, handle, SOLVABLE_HEADEREND, headerend);
- if (gotpkgid)
- repodata_set_bin_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
- if (chksumh)
- repodata_set_bin_checksum(data, handle, SOLVABLE_CHECKSUM, chksumtype, solv_chksum_get(chksumh, 0));
- }
+ return 0;
+ }
+ if (chksumh)
+ solv_chksum_add(chksumh, lead, 16);
+ if (getu32(lead) != 0x8eade801)
+ {
+ pool_error(pool, -1, "%s: bad header", rpm);
+ fclose(fp);
+ return 0;
+ }
+ sigcnt = getu32(lead + 8);
+ sigdsize = getu32(lead + 12);
+ if (sigcnt >= 0x100000 || sigdsize >= 0x800000)
+ {
+ pool_error(pool, -1, "%s: bad header", rpm);
+ fclose(fp);
+ return 0;
+ }
+ l = sigdsize + sigcnt * 16;
+ headerend = headerstart + 16 + l;
+ if (l > rpmheadsize)
+ {
+ rpmheadsize = l + 128;
+ rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
+ }
+ if (fread(rpmhead->data, l, 1, fp) != 1)
+ {
+ pool_error(pool, -1, "%s: unexpected EOF", rpm);
+ fclose(fp);
+ return 0;
}
if (chksumh)
- chksumh = solv_chksum_free(chksumh, 0);
+ solv_chksum_add(chksumh, rpmhead->data, l);
+ rpmhead->cnt = sigcnt;
+ rpmhead->dcnt = sigdsize;
+ rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
+ if (headexists(rpmhead, TAG_PATCHESNAME))
+ {
+ /* this is a patch rpm, ignore */
+ pool_error(pool, -1, "%s: is patch rpm", rpm);
+ fclose(fp);
+ return 0;
+ }
+ payloadformat = headstring(rpmhead, TAG_PAYLOADFORMAT);
+ if (payloadformat && !strcmp(payloadformat, "drpm"))
+ {
+ /* this is a delta rpm */
+ pool_error(pool, -1, "%s: is delta rpm", rpm);
+ fclose(fp);
+ return 0;
+ }
+ if (chksumh)
+ while ((l = fread(lead, 1, sizeof(lead), fp)) > 0)
+ solv_chksum_add(chksumh, lead, l);
+ fclose(fp);
+ s = pool_id2solvable(pool, repo_add_solvable(repo));
+ if (!rpm2solv(pool, repo, data, s, rpmhead, flags))
+ {
+ repo_free_solvable(repo, s - pool->solvables, 1);
+ return 0;
+ }
+ repodata_set_location(data, s - pool->solvables, 0, 0, rpm);
+ if (S_ISREG(stb.st_mode))
+ repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
+ repodata_set_num(data, s - pool->solvables, SOLVABLE_HEADEREND, headerend);
+ if (gotpkgid)
+ repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
+ if (chksumh)
+ {
+ repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_CHECKSUM, chksumtype, solv_chksum_get(chksumh, 0));
+ chksumh = solv_chksum_free(chksumh, 0);
+ }
if (rpmhead)
solv_free(rpmhead);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- return 0;
-}
-
-Id
-repo_add_rpm(Repo *repo, const char *rpm, int flags)
-{
- int end = repo->end;
- repo_add_rpms(repo, &rpm, 1, flags);
- if (end == repo->end)
- return 0;
- else
- return repo->end - 1;
+ return s - pool->solvables;
}
static inline void
@@ -2493,7 +2482,7 @@ rpm_byfp(FILE *fp, const char *name, void **statep)
}
sigcnt = getu32(lead + 96 + 8);
sigdsize = getu32(lead + 96 + 12);
- if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
+ if (sigcnt >= 0x100000 || sigdsize >= 0x100000)
{
fprintf(stderr, "%s: bad signature header\n", name);
return 0;
@@ -2524,7 +2513,7 @@ rpm_byfp(FILE *fp, const char *name, void **statep)
}
sigcnt = getu32(lead + 8);
sigdsize = getu32(lead + 12);
- if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
+ if (sigcnt >= 0x100000 || sigdsize >= 0x800000)
{
fprintf(stderr, "%s: bad header\n", name);
fclose(fp);
@@ -3162,47 +3151,55 @@ repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags)
return 0;
}
-int
-repo_add_pubkeys(Repo *repo, const char **keys, int nkeys, int flags)
+Id
+repo_add_pubkey(Repo *repo, const char *key, int flags)
{
Pool *pool = repo->pool;
Repodata *data;
Solvable *s;
char *buf;
- int i, bufl, l, ll;
+ int bufl, l, ll;
FILE *fp;
data = repo_add_repodata(repo, flags);
buf = 0;
bufl = 0;
- for (i = 0; i < nkeys; i++)
+ if ((fp = fopen(key, "r")) == 0)
{
- if ((fp = fopen(keys[i], "r")) == 0)
+ pool_error(pool, -1, "%s: %s", key, strerror(errno));
+ return 0;
+ }
+ for (l = 0; ;)
+ {
+ if (bufl - l < 4096)
{
- perror(keys[i]);
- continue;
+ bufl += 4096;
+ buf = solv_realloc(buf, bufl);
}
- for (l = 0; ;)
+ ll = fread(buf, 1, bufl - l, fp);
+ if (ll < 0)
{
- if (bufl - l < 4096)
- {
- bufl += 4096;
- buf = solv_realloc(buf, bufl);
- }
- ll = fread(buf, 1, bufl - l, fp);
- if (ll <= 0)
- break;
- l += ll;
+ fclose(fp);
+ pool_error(pool, -1, "%s: %s", key, strerror(errno));
+ return 0;
}
- buf[l] = 0;
- fclose(fp);
- s = pool_id2solvable(pool, repo_add_solvable(repo));
- pubkey2solvable(s, data, buf);
+ if (ll == 0)
+ break;
+ l += ll;
+ }
+ buf[l] = 0;
+ fclose(fp);
+ s = pool_id2solvable(pool, repo_add_solvable(repo));
+ if (!pubkey2solvable(s, data, buf))
+ {
+ repo_free_solvable(repo, s - pool->solvables, 1);
+ solv_free(buf);
+ return 0;
}
solv_free(buf);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
- return 0;
+ return s - pool->solvables;
}
#endif /* ENABLE_RPMDB_PUBKEY */
diff --git a/ext/repo_rpmdb.h b/ext/repo_rpmdb.h
index 9fcce63..f8251cb 100644
--- a/ext/repo_rpmdb.h
+++ b/ext/repo_rpmdb.h
@@ -11,10 +11,9 @@
struct headerToken_s;
extern int repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags);
-extern int repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags);
extern Id repo_add_rpm(Repo *repo, const char *rpm, int flags);
extern int repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags);
-extern int repo_add_pubkeys(Repo *repo, const char **keys, int nkeys, int flags);
+extern Id repo_add_pubkey(Repo *repo, const char *key, int flags);
#define RPMDB_REPORT_PROGRESS (1 << 8)
#define RPM_ADD_WITH_PKGID (1 << 9)
diff --git a/tools/archpkgs2solv.c b/tools/archpkgs2solv.c
index 811885c..1f89929 100644
--- a/tools/archpkgs2solv.c
+++ b/tools/archpkgs2solv.c
@@ -52,7 +52,7 @@ main(int argc, char **argv)
const char **pkgs = 0;
char *manifest = 0;
int manifest0 = 0;
- int i, c, npkgs = 0;
+ int i, c, res, npkgs = 0;
Pool *pool = pool_create();
Repo *repo;
FILE *fp;
@@ -116,11 +116,12 @@ main(int argc, char **argv)
}
repo = repo_create(pool, "archpkgs2solv");
repo_add_repodata(repo, 0);
+ res = 0;
for (i = 0; i < npkgs; i++)
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);
+ res = 1;
}
repo_internalize(repo);
tool_write(repo, basefile, 0);
@@ -128,6 +129,6 @@ main(int argc, char **argv)
for (c = 0; c < npkgs; c++)
solv_free((char *)pkgs[c]);
solv_free(pkgs);
- exit(0);
+ exit(res);
}
diff --git a/tools/common_write.c b/tools/common_write.c
index ba40f35..75c75b5 100644
--- a/tools/common_write.c
+++ b/tools/common_write.c
@@ -193,7 +193,7 @@ write_info(Repo *repo, FILE *fp, int (*keyfilter)(Repo *repo, Repokey *key, void
repodata_add_flexarray(info, SOLVID_META, REPOSITORY_EXTERNAL, h);
}
-int
+void
tool_write(Repo *repo, const char *basename, const char *attrname)
{
Repodata *data;
@@ -316,7 +316,6 @@ tool_write(Repo *repo, const char *basename, const char *attrname)
free(languages[i]);
solv_free(languages);
repodata_free(info);
- return 0;
}
if (attrname)
{
@@ -334,5 +333,4 @@ tool_write(Repo *repo, const char *basename, const char *attrname)
exit(1);
}
repodata_free(info);
- return 0;
}
diff --git a/tools/common_write.h b/tools/common_write.h
index 22676c9..7630edd 100644
--- a/tools/common_write.h
+++ b/tools/common_write.h
@@ -10,6 +10,6 @@
#include "repo.h"
-int tool_write(Repo *repo, const char *basename, const char *attrname);
+void tool_write(Repo *repo, const char *basename, const char *attrname);
#endif
diff --git a/tools/rpms2solv.c b/tools/rpms2solv.c
index 79a3684..29e851a 100644
--- a/tools/rpms2solv.c
+++ b/tools/rpms2solv.c
@@ -52,9 +52,10 @@ main(int argc, char **argv)
const char **rpms = 0;
char *manifest = 0;
int manifest0 = 0;
- int c, nrpms = 0;
+ int c, i, res, nrpms = 0;
Pool *pool = pool_create();
Repo *repo;
+ Repodata *data;
FILE *fp;
char buf[4096], *p;
const char *basefile = 0;
@@ -111,16 +112,22 @@ main(int argc, char **argv)
rpms[nrpms++] = strdup(argv[optind++]);
}
repo = repo_create(pool, "rpms2solv");
- if (repo_add_rpms(repo, rpms, nrpms, 0))
+ repo_add_repodata(repo, 0);
+ res = 0;
+ for (i = 0; i < nrpms; i++)
{
- fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
- exit(1);
+ if (repo_add_rpm(repo, rpms[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE))
+ {
+ fprintf(stderr, "rpms2solv: %s\n", pool_errstr(pool));
+ res = 1;
+ }
}
+ repo_internalize(repo);
tool_write(repo, basefile, 0);
pool_free(pool);
for (c = 0; c < nrpms; c++)
free((char *)rpms[c]);
solv_free(rpms);
- exit(0);
+ exit(res);
}