[Rpm-maint] [Patch] rpmtsAddInstallElement() failure checking in python
Panu Matilainen
pmatilai at redhat.com
Tue May 22 08:26:50 UTC 2007
Attached patch (mentioned in the payload format patch commentary) makes
the python bindings throw an exception when ts.addInstall() fails, whereas
previously it would just silently fail.
pyrpmError might be a better exception to raise, the TypeError is there
because in theory, any callers should already be catching TypeError as
there are a couple of ways it could raise a TypeError exception as is. But
IIRC at least yum doesn't because the other causes are somewhat obscure.
OTOH if rpmtsAddInstallElement() fails the install will fail in one way or
the other anyway, it's just a matter of failing in a different way.
Another alternative could be returning the result from
rpmtsAddInstallElement() directly, so that it'd be possible to check but
unmodified clients would behave the same as they are now - silently
ignoring and failing late.
Raising an exception seems like the right thing to do, but do people think
it's too disruptive a change for a maintenance release of rpm?
- Panu -
---
diff -r 4c3b70808142 python/rpmts-py.c
--- a/python/rpmts-py.c Thu May 17 11:06:55 2007 +0100
+++ b/python/rpmts-py.c Fri May 18 15:04:37 2007 +0300
@@ -245,10 +245,16 @@ fprintf(stderr, "*** rpmts_AddInstall(%p
} else if (how && !strcmp(how, "u"))
isUpgrade = 1;
+ int rc = 0;
if (how && !strcmp(how, "a"))
rpmtsAddAvailableElement(s->ts, hdrGetHeader(h), key);
else
- rpmtsAddInstallElement(s->ts, hdrGetHeader(h), key, isUpgrade, NULL);
+ rc = rpmtsAddInstallElement(s->ts, hdrGetHeader(h), key, isUpgrade, NULL);
+ if (rc) {
+ PyErr_SetString(PyExc_TypeError, "adding package to transaction failed");
+ return NULL;
+ }
+
/* This should increment the usage count for me */
if (key)
More information about the Rpm-maint
mailing list