summaryrefslogtreecommitdiff
path: root/lib/rpmte.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-11-25 11:51:30 +0200
committerPanu Matilainen <pmatilai@redhat.com>2008-11-26 17:35:12 +0200
commit8690479c3c4a1434624341db8b5a1f3914b26911 (patch)
tree5fab7f624bc3402fd47633d32b76480e6d139b79 /lib/rpmte.c
parent1cbb50c7b99803613b3dea967bc51b3e2687ffe5 (diff)
downloadrpm-8690479c3c4a1434624341db8b5a1f3914b26911.tar.gz
rpm-8690479c3c4a1434624341db8b5a1f3914b26911.tar.bz2
rpm-8690479c3c4a1434624341db8b5a1f3914b26911.zip
Teach rpmteOpen() and rpmteClose() about TR_REMOVED type
- for open, fetch the header from rpmdb, closing is nearly a no-op - allows install and erase behave more symmetrically, and also paving way for better erase callback notifications and other things - watch out for them refcounts...
Diffstat (limited to 'lib/rpmte.c')
-rw-r--r--lib/rpmte.c77
1 files changed, 52 insertions, 25 deletions
diff --git a/lib/rpmte.c b/lib/rpmte.c
index 154c01b19..50ac61626 100644
--- a/lib/rpmte.c
+++ b/lib/rpmte.c
@@ -9,6 +9,7 @@
#include <rpm/rpmds.h>
#include <rpm/rpmfi.h>
#include <rpm/rpmts.h>
+#include <rpm/rpmdb.h>
#include "lib/rpmte_internal.h"
@@ -619,45 +620,71 @@ rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
int rpmteOpen(rpmte te, rpmts ts)
{
- int rc = 0;
+ Header h = NULL;
if (te == NULL || ts == NULL)
goto exit;
- te->h = NULL;
- te->fd = rpmtsNotify(ts, te, RPMCALLBACK_INST_OPEN_FILE, 0, 0);
- if (te->fd != NULL) {
- rpmVSFlags ovsflags;
- rpmRC pkgrc;
-
- ovsflags = rpmtsSetVSFlags(ts, rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD);
- pkgrc = rpmReadPackageFile(ts, rpmteFd(te), rpmteNEVRA(te), &te->h);
- rpmtsSetVSFlags(ts, ovsflags);
- switch (pkgrc) {
- default:
- rpmteClose(te, ts);
- break;
- case RPMRC_NOTTRUSTED:
- case RPMRC_NOKEY:
- case RPMRC_OK:
- rc = 1;
- break;
+ rpmteSetHeader(te, NULL);
+ switch (te->type) {
+ case TR_ADDED:
+ te->h = NULL;
+ te->fd = rpmtsNotify(ts, te, RPMCALLBACK_INST_OPEN_FILE, 0, 0);
+ if (te->fd != NULL) {
+ rpmVSFlags ovsflags;
+ rpmRC pkgrc;
+
+ ovsflags = rpmtsSetVSFlags(ts, rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD);
+ pkgrc = rpmReadPackageFile(ts, rpmteFd(te), rpmteNEVRA(te), &h);
+ rpmtsSetVSFlags(ts, ovsflags);
+ switch (pkgrc) {
+ default:
+ rpmteClose(te, ts);
+ break;
+ case RPMRC_NOTTRUSTED:
+ case RPMRC_NOKEY:
+ case RPMRC_OK:
+ break;
+ }
}
+ break;
+ case TR_REMOVED: {
+ unsigned int rec = rpmteDBInstance(te);
+ rpmdbMatchIterator mi;
+
+ /* eventually we'll want notifications for erase open too */
+ mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, &rec, sizeof(rec));
+ /* iterator returns weak refs, grab hold of header */
+ if ((h = rpmdbNextIterator(mi)))
+ h = headerLink(h);
+ mi = rpmdbFreeIterator(mi);
+ }
+ break;
+ }
+ if (h != NULL) {
+ rpmteSetHeader(te, h);
+ headerFree(h);
}
exit:
- return rc;
+ return (h != NULL);
}
int rpmteClose(rpmte te, rpmts ts)
{
- int rc = 0;
- if (te != NULL && ts != NULL) {
+ if (te == NULL || ts == NULL)
+ return 0;
+
+ switch (te->type) {
+ case TR_ADDED:
rpmtsNotify(ts, te, RPMCALLBACK_INST_CLOSE_FILE, 0, 0);
te->fd = NULL;
- te->h = headerFree(te->h);
- rc = 1;
+ break;
+ case TR_REMOVED:
+ /* eventually we'll want notifications for erase open too */
+ break;
}
- return rc;
+ rpmteSetHeader(te, NULL);
+ return 1;
}
int rpmteMarkFailed(rpmte te, rpmts ts)