Fix python ts.addErase() not raising exception on not-found packages
The code would only raise an exception if TransactionSetCore.addErase()
returned an error, but the catch is that with many kinds of argument
types we'd silently skip the whole addition because no headers were found.
This looks to be a regression introduced some eleven years ago in
commit 9b20c706a4
.
As a special case, a match iterator argument will not raise an exception
if it doesn't actually match anything.
Fixes: #1214
This commit is contained in:
parent
25e856a6d4
commit
09a3d5c23b
|
@ -85,14 +85,22 @@ class TransactionSet(TransactionSetCore):
|
|||
|
||||
def addErase(self, item):
|
||||
hdrs = []
|
||||
if isinstance(item, rpm.hdr):
|
||||
hdrs = [item]
|
||||
elif isinstance(item, rpm.mi):
|
||||
# match iterators are passed on as-is
|
||||
if isinstance(item, rpm.mi):
|
||||
hdrs = item
|
||||
elif isinstance(item, int):
|
||||
hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item)
|
||||
elif isinstance(item, str):
|
||||
hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item)
|
||||
elif isinstance(item, rpm.hdr):
|
||||
hdrs.append(item)
|
||||
elif isinstance(item, (int, str)):
|
||||
if isinstance(item, int):
|
||||
dbi = rpm.RPMDBI_PACKAGES
|
||||
else:
|
||||
dbi = rpm.RPMDBI_LABEL
|
||||
|
||||
for h in self.dbMatch(dbi, item):
|
||||
hdrs.append(h)
|
||||
|
||||
if not hdrs:
|
||||
raise rpm.error("package not installed")
|
||||
else:
|
||||
raise TypeError("invalid type %s" % type(item))
|
||||
|
||||
|
@ -100,10 +108,6 @@ class TransactionSet(TransactionSetCore):
|
|||
if not TransactionSetCore.addErase(self, h):
|
||||
raise rpm.error("adding erasure to transaction failed")
|
||||
|
||||
# garbage collection should take care but just in case...
|
||||
if isinstance(hdrs, rpm.mi):
|
||||
del hdrs
|
||||
|
||||
def run(self, callback, data):
|
||||
rc = TransactionSetCore.run(self, callback, data, self._probFilter)
|
||||
|
||||
|
|
|
@ -259,6 +259,28 @@ for e in ts:
|
|||
[foo-1.0-1.noarch]
|
||||
)
|
||||
|
||||
RPMPY_TEST([add erasure to transaction],[
|
||||
ts = rpm.ts()
|
||||
for i in ['foo', 1234]:
|
||||
myprint('addErase %s' % i)
|
||||
try:
|
||||
ts.addErase(i)
|
||||
except rpm.error as err:
|
||||
myprint(err)
|
||||
myprint('addErase mi')
|
||||
mi = ts.dbMatch('name', 'foo')
|
||||
try:
|
||||
ts.addErase(mi)
|
||||
except rpm.error as err:
|
||||
myprint(err)
|
||||
],
|
||||
[addErase foo
|
||||
package not installed
|
||||
addErase 1234
|
||||
package not installed
|
||||
addErase mi]
|
||||
)
|
||||
|
||||
RPMPY_TEST([add bogus package to transaction 1],[
|
||||
ts = rpm.ts()
|
||||
h = rpm.hdr()
|
||||
|
|
Loading…
Reference in New Issue