summaryrefslogtreecommitdiff
path: root/lib/rpmdb.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-28 09:35:13 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-28 09:45:35 +0300
commit63f24f2307426106a0bccde91c1b8cfa8bc5da36 (patch)
treeb5f54f0dd47b660220dd34bba52fcfd1627dcb31 /lib/rpmdb.c
parent2a1c813d495c5b05576f2feff6679aed20e587d5 (diff)
downloadrpm-63f24f2307426106a0bccde91c1b8cfa8bc5da36.tar.gz
rpm-63f24f2307426106a0bccde91c1b8cfa8bc5da36.tar.bz2
rpm-63f24f2307426106a0bccde91c1b8cfa8bc5da36.zip
Unify rpmdbAdd() and rpmdbRemove() debug logging
- move the debugging out of the loop, we only print once for a given tag anyway - dumb helper function for prepping the actual output
Diffstat (limited to 'lib/rpmdb.c')
-rw-r--r--lib/rpmdb.c54
1 files changed, 21 insertions, 33 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index fc7d9f22a..a1bb89e1f 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -2399,6 +2399,22 @@ static int td2key(rpmtd tagdata, DBT *key)
return 1;
}
+static void logAddRemove(int removing, rpmtd tagdata)
+{
+ rpm_count_t c = rpmtdCount(tagdata);
+ if (c == 1 && rpmtdType(tagdata) == RPM_STRING_TYPE) {
+ rpmlog(RPMLOG_DEBUG, "%s \"%s\" %s %s index.\n",
+ removing ? "removing" : "adding", rpmtdGetString(tagdata),
+ removing ? "from" : "to",
+ rpmTagGetName(rpmtdTag(tagdata)));
+ } else if (c > 0) {
+ rpmlog(RPMLOG_DEBUG, "%s %d entries %s %s index.\n",
+ removing ? "removing" : "adding", c,
+ removing ? "from" : "to",
+ rpmTagGetName(rpmtdTag(tagdata)));
+ }
+}
+
/* XXX psm.c */
int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum,
rpmts ts,
@@ -2449,7 +2465,7 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum,
for (dbix = 0; dbix < dbiTags.max; dbix++) {
dbiIndex dbi;
rpmTag rpmtag;
- int xx, printed = 0;
+ int xx = 0;
struct rpmtd_s tagdata;
dbi = NULL;
@@ -2495,6 +2511,9 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum,
xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR);
rpmtdInit(&tagdata);
+
+ logAddRemove(1, &tagdata);
+
while (rpmtdNext(&tagdata) >= 0) {
dbiIndexSet set;
@@ -2502,21 +2521,6 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum,
continue;
}
- if (!printed) {
- int stringvalued = (rpmtdType(&tagdata) == RPM_STRING_TYPE);
- rpm_count_t c = rpmtdCount(&tagdata);
- if (c == 1 && stringvalued) {
- rpmlog(RPMLOG_DEBUG,
- "removing \"%s\" from %s index.\n",
- (char *)key.data, rpmTagGetName(rpmtag));
- } else {
- rpmlog(RPMLOG_DEBUG,
- "removing %d entries from %s index.\n",
- c, rpmTagGetName(rpmtag));
- }
- printed++;
- }
-
/* XXX
* This is almost right, but, if there are duplicate tag
* values, there will be duplicate attempts to remove
@@ -2781,10 +2785,9 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
dbi = dbiOpen(db, rpmtag, 0);
if (dbi != NULL) {
- int printed = 0;
-
xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR);
+ logAddRemove(0, &tagdata);
while (rpmtdNext(&tagdata) >= 0) {
dbiIndexSet set;
int i;
@@ -2822,21 +2825,6 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
continue;
}
- if (!printed) {
- int stringvalued = (rpmtdType(&tagdata) == RPM_STRING_TYPE);
- rpm_count_t c = rpmtdCount(&tagdata);
- if (c == 1 && stringvalued) {
- rpmlog(RPMLOG_DEBUG,
- "adding \"%s\" to %s index.\n",
- (char *)key.data, rpmTagGetName(rpmtag));
- } else {
- rpmlog(RPMLOG_DEBUG,
- "adding %d entries to %s index.\n",
- c, rpmTagGetName(rpmtag));
- }
- printed++;
- }
-
/*
* XXX with duplicates, an accurate data value and
* DB_GET_BOTH is needed.