diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py index ab13ccd92..991fd9a91 100644 --- a/python/rpm/transaction.py +++ b/python/rpm/transaction.py @@ -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) diff --git a/tests/rpmpython.at b/tests/rpmpython.at index 195784147..58a3de671 100644 --- a/tests/rpmpython.at +++ b/tests/rpmpython.at @@ -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()