From 4294365db5d78909ae5a490e0714db379502cd80 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 4 Jul 2008 11:25:38 +0000 Subject: - add traverse_tag_find() --- NEWS | 2 ++ URPM.pm | 6 ++++++ URPM.xs | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/NEWS b/NEWS index 4719b89..51d2efc 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- add traverse_tag_find() + Version 3.16 - 26 June 2008, by Pascal "Pixel" Rigaux - when not selecting a package because already installed, diff --git a/URPM.pm b/URPM.pm index d9630be..63f7de2 100644 --- a/URPM.pm +++ b/URPM.pm @@ -453,6 +453,12 @@ $names is a reference to an array, holding the acceptable values of the said tag for the searched variables. Then, $callback is called for each matching package in the DB. +=item $db->traverse_tag_find($tag,$name,$callback) + +Quite similar to C, but stops when $callback returns true. + +(also note that only one $name is handled) + =item $db->create_transaction($prefix) Creates and returns a new transaction (an C object) on the diff --git a/URPM.xs b/URPM.xs index 5a30d22..679bede 100644 --- a/URPM.xs +++ b/URPM.xs @@ -2921,6 +2921,49 @@ Db_traverse_tag(db,tag,names,callback) OUTPUT: RETVAL +int +Db_traverse_tag_find(db,tag,name,callback) + URPM::DB db + char *tag + char *name + SV *callback + PREINIT: + Header header; + rpmdbMatchIterator mi; + CODE: + int rpmtag = rpmtag_from_string(tag); + int found = 0; + + db->ts = rpmtsLink(db->ts, "URPM::DB::traverse_tag"); + ts_nosignature(db->ts); + mi = rpmtsInitIterator(db->ts, rpmtag, name, 0); + while ((header = rpmdbNextIterator(mi))) { + dSP; + URPM__Package pkg = calloc(1, sizeof(struct s_Package)); + + pkg->flag = FLAG_ID_INVALID | FLAG_NO_HEADER_FREE; + pkg->h = header; + + PUSHMARK(SP); + XPUSHs(sv_2mortal(sv_setref_pv(newSVpv("", 0), "URPM::Package", pkg))); + PUTBACK; + + int count = call_sv(callback, G_SCALAR); + + SPAGAIN; + pkg->h = 0; /* avoid using it anymore, in case it has been copied inside callback */ + + if (count == 1 && POPi) { + found = 1; + break; + } + } + rpmdbFreeIterator(mi); + rpmtsFree(db->ts); + RETVAL = found; + OUTPUT: + RETVAL + URPM::Transaction Db_create_transaction(db, prefix="/") URPM::DB db -- cgit v1.2.1