aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2002-07-04 17:53:22 +0000
committerFrancois Pons <fpons@mandriva.com>2002-07-04 17:53:22 +0000
commit9b28843da9c6be2e3173292f72e881f011521d92 (patch)
treec5b6ff2515869a98b73ed3b13c630acecd859210
parent20030d3ddf748fb56eb842a0288d090a4c4bb0c6 (diff)
downloadperl-URPM-9b28843da9c6be2e3173292f72e881f011521d92.tar
perl-URPM-9b28843da9c6be2e3173292f72e881f011521d92.tar.gz
perl-URPM-9b28843da9c6be2e3173292f72e881f011521d92.tar.bz2
perl-URPM-9b28843da9c6be2e3173292f72e881f011521d92.tar.xz
perl-URPM-9b28843da9c6be2e3173292f72e881f011521d92.zip
0.07-1mdk
-rw-r--r--URPM.pm2
-rw-r--r--URPM.xs336
-rw-r--r--perl-URPM.spec8
-rw-r--r--typemap1
4 files changed, 326 insertions, 21 deletions
diff --git a/URPM.pm b/URPM.pm
index a6ce815..9790b4d 100644
--- a/URPM.pm
+++ b/URPM.pm
@@ -6,7 +6,7 @@ use vars qw($VERSION @ISA);
require DynaLoader;
@ISA = qw(DynaLoader);
-$VERSION = '0.06';
+$VERSION = '0.07';
bootstrap URPM $VERSION;
diff --git a/URPM.xs b/URPM.xs
index 5c080e0..62def76 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -35,7 +35,13 @@ struct s_Package {
Header h;
};
+struct s_Transaction {
+ rpmdb db;
+ rpmTransactionSet ts;
+};
+
typedef rpmdb URPM__DB;
+typedef struct s_Transaction* URPM__Transaction;
typedef struct s_Package* URPM__Package;
#define FLAG_ID 0x001fffffU
@@ -1539,24 +1545,9 @@ Pkg_set_rflags(pkg, ...)
MODULE = URPM PACKAGE = URPM::DB PREFIX = Db_
URPM::DB
-Db_open(prefix="/")
- char *prefix
- PREINIT:
- rpmdb db;
- rpmErrorCallBackType old_cb;
- CODE:
- read_config_files();
- old_cb = rpmErrorSetCallback(callback_empty);
- rpmSetVerbosity(RPMMESS_FATALERROR);
- RETVAL = rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0 ? db : NULL;
- rpmErrorSetCallback(old_cb);
- rpmSetVerbosity(RPMMESS_NORMAL);
- OUTPUT:
- RETVAL
-
-URPM::DB
-Db_open_rw(prefix="/")
+Db_open(prefix="/", write_perm=0)
char *prefix
+ int write_perm
PREINIT:
rpmdb db;
rpmErrorCallBackType old_cb;
@@ -1564,7 +1555,7 @@ Db_open_rw(prefix="/")
read_config_files();
old_cb = rpmErrorSetCallback(callback_empty);
rpmSetVerbosity(RPMMESS_FATALERROR);
- RETVAL = rpmdbOpen(prefix, &db, O_RDWR | O_CREAT, 0644) == 0 ? db : NULL;
+ RETVAL = rpmdbOpen(prefix, &db, write_perm ? O_RDWR | O_CREAT : O_RDONLY, 0644) == 0 ? db : NULL;
rpmErrorSetCallback(old_cb);
rpmSetVerbosity(RPMMESS_NORMAL);
OUTPUT:
@@ -1695,6 +1686,315 @@ Db_traverse_tag(db,tag,names,callback)
OUTPUT:
RETVAL
+URPM::Transaction
+Db_create_transaction(db, prefix="/")
+ URPM::DB db
+ char *prefix
+ CODE:
+ if ((RETVAL = malloc(sizeof(struct s_Transaction))) != NULL) {
+ RETVAL->db = db;
+ RETVAL->ts = rpmtransCreateSet(db, prefix);
+ }
+ OUTPUT:
+ RETVAL
+
+
+MODULE = URPM PACKAGE = URPM::Transaction PREFIX = Trans_
+
+void
+Trans_DESTROY(trans)
+ URPM::Transaction trans
+ CODE:
+ /* db should be SV with reference count updated */
+ rpmtransFree(trans->ts);
+ free(trans);
+
+int
+Trans_add_package(trans, pkg, update)
+ URPM::Transaction trans
+ SV* pkg
+ int update
+ PREINIT:
+ URPM__Package _pkg;
+ CODE:
+ if (sv_derived_from(ST(0), "URPM::Package")) {
+ IV tmp = SvIV((SV*)SvRV(ST(0)));
+ _pkg = INT2PTR(URPM__Package,tmp);
+ } else croak("pkg is not of type URPM::Package");
+ RETVAL = _pkg->h && rpmtransAddPackage(trans->ts, _pkg->h, NULL, /* SvREFCNT_inc(pkg) */ pkg, update, NULL) == 0;
+ OUTPUT:
+ RETVAL
+
+int
+Trans_remove_package(trans, name)
+ URPM::Transaction trans
+ char *name
+ PREINIT:
+ Header h;
+ rpmdbMatchIterator mi;
+ int count = 0;
+ CODE:
+ mi = rpmdbInitIterator(trans->db, RPMDBI_LABEL, name, 0);
+ while (h = rpmdbNextIterator(mi)) {
+ unsigned int recOffset = rpmdbGetIteratorOffset(mi);
+ if (recOffset) {
+ rpmtransRemovePackage(trans->ts, recOffset);
+ ++count;
+ }
+ }
+ rpmdbFreeIterator(mi);
+ RETVAL=count;
+ OUTPUT:
+ RETVAL
+
+void
+Trans_check(trans)
+ URPM::Transaction trans
+ PREINIT:
+ I32 gimme = GIMME_V;
+ rpmDependencyConflict conflicts;
+ int num_conflicts;
+ PPCODE:
+ if (rpmdepCheck(trans->ts, &conflicts, &num_conflicts)) {
+ if (gimme == G_SCALAR) {
+ XPUSHs(sv_2mortal(newSViv(0)));
+ } else if (gimme == G_ARRAY) {
+ XPUSHs(sv_2mortal(newSVpv("error while checking dependencies", 0)));
+ }
+ } else if (conflicts) {
+ if (gimme == G_SCALAR) {
+ XPUSHs(sv_2mortal(newSViv(0)));
+ } else if (gimme == G_ARRAY) {
+ char buff[1024];
+ int i;
+
+ for (i = 0; i < num_conflicts; ++i) {
+ char *p = buff;
+
+ p += snprintf(p, sizeof(buff) - (p-buff), "%s@%s",
+ conflicts[i].sense == RPMDEP_SENSE_REQUIRES ? "requires" : "conflicts",
+ conflicts[i].needsName);
+ if (sizeof(buff) - (p-buff) > 4 && conflicts[i].needsFlags & RPMSENSE_SENSEMASK) {
+ *p++ = ' ';
+ if (conflicts[i].needsFlags & RPMSENSE_LESS) *p++ = '<';
+ if (conflicts[i].needsFlags & RPMSENSE_GREATER) *p++ = '>';
+ if (conflicts[i].needsFlags & RPMSENSE_EQUAL) *p++ = '=';
+ if ((conflicts[i].needsFlags & RPMSENSE_SENSEMASK) == RPMSENSE_EQUAL) *p++ = '=';
+ *p++ = ' ';
+ p += snprintf(p, sizeof(buff) - (p-buff), "%s@%s-%s-%s",
+ conflicts[i].needsVersion,
+ conflicts[i].byName, conflicts[i].byVersion, conflicts[i].byRelease);
+ }
+ *p = 0;
+ XPUSHs(sv_2mortal(newSVpv(buff, p-buff)));
+ }
+ }
+ rpmdepFreeConflicts(conflicts, num_conflicts);
+ } else if (gimme == G_SCALAR) {
+ XPUSHs(sv_2mortal(newSViv(1)));
+ }
+
+int
+Trans_order(trans)
+ URPM::Transaction trans
+ PREINIT:
+ I32 gimme = GIMME_V;
+ PPCODE:
+ if (rpmdepOrder(trans->ts) == 0) {
+ if (gimme == G_SCALAR) {
+ XPUSHs(sv_2mortal(newSViv(1)));
+ }
+ } else {
+ if (gimme == G_SCALAR) {
+ XPUSHs(sv_2mortal(newSViv(0)));
+ } else if (gimme == G_ARRAY) {
+ XPUSHs(sv_2mortal(newSVpv("error while ordering dependencies", 0)));
+ }
+ }
+
+void
+Trans_run(trans, data, ...)
+ URPM::Transaction trans
+ SV *data
+ PREINIT:
+ /* available callback:
+ callback(data, 'open'|'close', pkg)
+ callback(data, 'trans'|'uninst'|'inst', pkg, 'start'|'progress'|'stop', amount, total)
+ */
+ SV* callback_open = NULL;
+ SV* callback_close = NULL;
+ SV* callback_trans = NULL;
+ SV* callback_uninst = NULL;
+ SV* callback_inst = NULL;
+ int min_delta = 200000;
+ rpmProblemSet probs;
+ int i;
+ void *rpmRunTransactions_callback(const void *h,
+ const rpmCallbackType what,
+ const unsigned long amount,
+ const unsigned long total,
+ const void * pkgKey,
+ void * data) {
+ static int last_amount;
+ static FD_t fd = NULL;
+ static struct timeval tprev;
+ static struct timeval tcurr;
+ long delta;
+ int i;
+ SV *callback = NULL;
+ char *callback_type = NULL;
+ char *callback_subtype = NULL;
+
+ switch (what) {
+ case RPMCALLBACK_INST_OPEN_FILE:
+ callback = callback_open; callback_type = "open"; break;
+
+ case RPMCALLBACK_INST_CLOSE_FILE:
+ callback = callback_close; callback_type = "close"; break;
+
+ case RPMCALLBACK_TRANS_START:
+ case RPMCALLBACK_TRANS_PROGRESS:
+ case RPMCALLBACK_TRANS_STOP:
+ callback = callback_trans; callback_type = "trans"; break;
+
+ case RPMCALLBACK_UNINST_START:
+ case RPMCALLBACK_UNINST_PROGRESS:
+ case RPMCALLBACK_UNINST_STOP:
+ callback = callback_uninst; callback_type = "uninst"; break;
+
+ case RPMCALLBACK_INST_START:
+ case RPMCALLBACK_INST_PROGRESS:
+ callback = callback_inst; callback_type = "inst"; break;
+ }
+
+ if (callback != NULL) {
+ switch (what) {
+ case RPMCALLBACK_TRANS_START:
+ case RPMCALLBACK_UNINST_START:
+ case RPMCALLBACK_INST_START:
+ callback_subtype = "start"; break;
+
+ case RPMCALLBACK_TRANS_PROGRESS:
+ case RPMCALLBACK_UNINST_PROGRESS:
+ case RPMCALLBACK_INST_PROGRESS:
+ gettimeofday(&tcurr, NULL);
+ delta = 1000000 * (tcurr.tv_sec - tprev.tv_sec) + (tcurr.tv_usec - tprev.tv_usec);
+ if (delta > 200000 || amount >= total - 1)
+ callback_subtype = "progress";
+ else
+ callback = NULL; /* avoid calling too often a given callback */
+ break;
+
+ case RPMCALLBACK_TRANS_STOP:
+ case RPMCALLBACK_UNINST_STOP:
+ callback_subtype = "stop"; break;
+ }
+
+ if (callback != NULL) {
+ /* now, a callback will be called for sure */
+ dSP;
+ PUSHMARK(sp);
+ XPUSHs(data);
+ XPUSHs(sv_2mortal(newSVpv(callback_type, 0)));
+ XPUSHs((SV *)pkgKey);
+ if (callback_subtype != NULL) {
+ XPUSHs(sv_2mortal(newSVpv(callback_subtype, 0)));
+ XPUSHs(sv_2mortal(newSViv(amount)));
+ XPUSHs(sv_2mortal(newSViv(total)));
+ }
+ PUTBACK;
+ i = perl_call_sv(callback, callback == callback_open ? G_SCALAR : G_DISCARD);
+ SPAGAIN;
+ if (i != 1 && callback == callback_open) croak("callback_open should return a file handle");
+ if (i == 1) {
+ i = POPi;
+ fd = fdDup(i);
+ fd = fdLink(fd, "persist perl-URPM");
+ PUTBACK;
+ return fd;
+ }
+ if (callback == callback_close) {
+ /* REFDEC on pkgKey */
+ fd = fdFree(fd, "persist perl-URPM");
+ if (fd) {
+ fdClose(fd);
+ fd = NULL;
+ }
+ }
+ }
+ }
+ return NULL;
+ }
+ PPCODE:
+ for (i = 2; i < items-1; i+=2) {
+ STRLEN len;
+ char *s = SvPV(ST(i), len);
+
+ if (len >= 9 && !memcmp(s, "callback_", 9)) {
+ if (len == 9+4 && !memcmp(s+9, "open", 4))
+ callback_open = ST(i+1);
+ else if (len == 9+5 && !memcmp(s+9, "close", 5))
+ callback_close = ST(i+1);
+ else if (len == 9+5 && !memcmp(s+9, "trans", 5))
+ callback_trans = ST(i+1);
+ else if (len == 9+6 && !memcmp(s+9, "uninst", 6))
+ callback_uninst = ST(i+1);
+ else if (len == 9+6 && !memcmp(s+9, "inst", 4))
+ callback_inst = ST(i+1);
+ } else if (len == 5 && !memcmp(s, "delta", 5))
+ min_delta = SvIV(ST(i+1));
+ }
+ if (rpmRunTransactions(trans->ts, rpmRunTransactions_callback, NULL, NULL, &probs, 0, 0)) {
+ EXTEND(SP, probs->numProblems);
+ for (i = 0; i < probs->numProblems; i++) {
+ const char *pkgNEVR = (probs->probs[i].pkgNEVR ? probs->probs[i].pkgNEVR : "");
+ const char *altNEVR = probs->probs[i].altNEVR ? probs->probs[i].altNEVR : "";
+ const char *s = probs->probs[i].str1 ? probs->probs[i].str1 : "";
+ SV *sv;
+
+ switch (probs->probs[i].type) {
+ case RPMPROB_BADARCH:
+ sv = newSVpvf("badarch@%s", pkgNEVR); break;
+
+ case RPMPROB_BADOS:
+ sv = newSVpvf("bados@%s", pkgNEVR); break;
+
+ case RPMPROB_PKG_INSTALLED:
+ sv = newSVpvf("installed@%s", pkgNEVR); break;
+
+ case RPMPROB_BADRELOCATE:
+ sv = newSVpvf("badrelocate@%s@%s", pkgNEVR, s); break;
+
+ case RPMPROB_NEW_FILE_CONFLICT:
+ case RPMPROB_FILE_CONFLICT:
+ sv = newSVpvf("conflicts@%s@%s@%s", pkgNEVR, altNEVR, s); break;
+
+ case RPMPROB_OLDPACKAGE:
+ sv = newSVpvf("installed@%s@%s", pkgNEVR, altNEVR); break;
+
+ case RPMPROB_DISKSPACE:
+ sv = newSVpvf("diskspace@%s@%s@%ld", pkgNEVR, s, probs->probs[i].ulong1); break;
+
+ case RPMPROB_DISKNODES:
+ sv = newSVpvf("disknodes@%s@%s@%ld", pkgNEVR, s, probs->probs[i].ulong1); break;
+
+ case RPMPROB_BADPRETRANS:
+ sv = newSVpvf("badpretrans@%s@%s@%s", pkgNEVR, s, strerror(probs->probs[i].ulong1)); break;
+
+ case RPMPROB_REQUIRES:
+ sv = newSVpvf("requires@%s@%s@%s", pkgNEVR, altNEVR+2); break;
+
+ case RPMPROB_CONFLICT:
+ sv = newSVpvf("conflicts@%s@%s", pkgNEVR, altNEVR+2); break;
+
+ default:
+ sv = newSVpvf("unknown@%s", pkgNEVR); break;
+ }
+ PUSHs(sv_2mortal(sv));
+ }
+ }
+
+
MODULE = URPM PACKAGE = URPM PREFIX = Urpm_
int
diff --git a/perl-URPM.spec b/perl-URPM.spec
index fa66d3d..209b2f6 100644
--- a/perl-URPM.spec
+++ b/perl-URPM.spec
@@ -1,7 +1,7 @@
%define name perl-URPM
%define real_name URPM
-%define version 0.06
-%define release 2mdk
+%define version 0.07
+%define release 1mdk
%{expand:%%define rpm_version %(rpm -q --queryformat '%{VERSION}-%{RELEASE}' rpm)}
@@ -48,6 +48,10 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Thu Jul 4 2002 François Pons <fpons@mandrakesoft.com> 0.07-1mdk
+- added transaction methods and URPM::Transaction type (for DrakX).
+- obsoleted URPM::DB::open_rw and removed it.
+
* Wed Jul 3 2002 François Pons <fpons@mandrakesoft.com> 0.06-2mdk
- fixed virtual provides obsoleted by other package (means kernel
is requested to be installed even if other kernel is installed).
diff --git a/typemap b/typemap
index d6a74d8..031189e 100644
--- a/typemap
+++ b/typemap
@@ -1,2 +1,3 @@
URPM::DB T_PTROBJ
+URPM::Transaction T_PTROBJ
URPM::Package T_PTROBJ