VALUE rpm_mi_next_iterator(VALUE mi) { Header hdr; hdr = rpmdbNextIterator(RPM_MI(mi)); if (hdr) return rpm_package_new_from_header(hdr); return Qnil; }
VALUE rpm_spec_get_build_restrictions(VALUE spec) { VALUE cache = rb_ivar_get(spec, id_rest); if (NIL_P(cache)) { cache = rpm_package_new_from_header(RPM_SPEC(spec)->buildRestrictions); rb_ivar_set(spec, id_rest, cache); } return cache; }
/* * @return [Array<RPM::Package>] Packages defined in the spec file */ VALUE rpm_spec_get_packages(VALUE spec) { VALUE pkg = rb_ivar_get(spec, id_pkg); if (NIL_P(pkg)) { Package p = RPM_SPEC(spec)->packages; pkg = rb_ary_new(); while (p != NULL) { if (p->fileList) rb_ary_push(pkg, rpm_package_new_from_header(p->header)); p = p->next; } rb_ivar_set(spec, id_pkg, pkg); } return pkg; }
static void* transaction_callback(const void* hd, const rpmCallbackType type, const rpmCallbackSize_t amount, const rpmCallbackSize_t total, fnpyKey key, rpmCallbackData data) { VALUE trans = (VALUE)data; FD_t fdt; const Header hdr = (Header)hd; VALUE sig; VALUE rv; sig = rb_struct_new(rpm_sCallbackData, INT2NUM(type), key ? (VALUE)key:Qnil, rpm_package_new_from_header(hdr), UINT2NUM(amount), UINT2NUM(total)); rv = rb_yield(sig); switch (type) { case RPMCALLBACK_INST_OPEN_FILE: if (TYPE(rv) != T_FILE) { rb_raise(rb_eTypeError, "illegal return value type"); } rb_ivar_set(trans, id_file, rv); fdt = fdDup(NUM2INT(rb_Integer(rv))); rb_ivar_set(trans, id_fdt, INT2NUM((long)fdt)); return fdt; case RPMCALLBACK_INST_CLOSE_FILE: Fclose((FD_t)NUM2LONG(rb_ivar_get(trans, id_fdt))); rb_ivar_set(trans, id_file, Qnil); rb_ivar_set(trans, id_fdt, Qnil); default: break; } return NULL; }
/* * Check the dependencies. * @return [Array<Dependency>, +nil+] If dependencies are not met returns an * array with dependencies. Otherwise +nil+. */ VALUE rpm_transaction_check(VALUE trans) { #if RPM_VERSION_CODE < RPM_VERSION(4,1,0) rpmDependencyConflict conflicts; int num; rpmdepCheck(RPM_TRANSACTION(trans), &conflicts, &num); if (num) { VALUE list = rb_ary_new(); register int i; for (i = 0; i < num; i++) { VALUE dep; switch (conflicts[i].sense) { case RPMDEP_SENSE_REQUIRES: dep = rpm_require_new(conflicts[i].needsName, rpm_version_new(conflicts[i].needsVersion), conflicts[i].needsFlags, rpm_package_new_from_header(conflicts[i].byHeader)); break; case RPMDEP_SENSE_CONFLICTS: dep = rpm_conflict_new(conflicts[i].needsName, rpm_version_new(conflicts[i].needsVersion), conflicts[i].needsFlags, rpm_package_new_from_header(conflicts[i].byHeader)); break; } rb_ary_push(list, dep); } rpmdepFreeConflicts(conflicts, num); return list; } return Qnil; #else int rc; rpmps ps; int num; VALUE list = Qnil; rc = rpmtsCheck(RPM_TRANSACTION(trans)); ps = rpmtsProblems(RPM_TRANSACTION(trans)); #if RPM_VERSION_CODE < RPM_VERSION(4,9,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0) /* get rid of duplicate problems */ rpmpsTrim(ps, RPMPROB_FILTER_NONE); #endif num = rpmpsNumProblems(ps); #ifdef RPMPS_OPAQUE rpmpsi psi = rpmpsInitIterator(ps); if (num > 0) { list = rb_ary_new(); } while (rpmpsNextIterator(psi) >= 0) { rpmProblem p = rpmpsGetProblem(psi); VALUE dep; switch (rpmProblemGetType(p)) { case RPMPROB_REQUIRES: { char *buf = strdup (rpmProblemGetAltNEVR(p)); /* TODO: zaki: NULL check*/ char *end; char *name = buf+2; char *relation = NULL; char *evr = NULL; rpmsenseFlags sense_flags = 0; end = strchr ( name, ' '); if ( end ) { *end = '\0'; relation = end + 1; end = strchr ( relation, ' '); if ( end ) { *end = '\0'; evr = end + 1; } for ( ; (*relation) != '\0'; relation++ ) { if ( (*relation) == '=' ) { sense_flags |= RPMSENSE_EQUAL; } else if ( (*relation) == '>' ) { sense_flags |= RPMSENSE_GREATER; } else if ( (*relation) == '<' ) { sense_flags |= RPMSENSE_LESS; } } } dep = rpm_require_new(name, rpm_version_new(evr ? evr : ""), sense_flags, package_new_from_NEVR( rpmProblemGetPkgNEVR(p) )); free ( buf ); rb_ary_push(list, dep); break; } default: break; } } #else if (ps != NULL && 0 < num) { rpmProblem p; int i; list = rb_ary_new(); for (i = 0; i < num; i++) { const char *altNEVR; VALUE dep; p = ps->probs + i; altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?"); if (p->ignoreProblem) continue; #if 0 /* XXX shouldn't be needed at all due to rpmpsTrim() */ /* Filter already appended problems. */ for (j = 0; j < i; j++) { if (!sameProblem(p, ps->probs + j)) break; } if (j < i) continue; #endif if ( p->type == RPMPROB_REQUIRES ) { char *buf = strdup ( altNEVR ); /* TODO: zaki: NULL check*/ char *end; char *name = buf+2; char *relation = NULL; char *evr = ""; rpmsenseFlags sense_flags = 0; end = strchr ( name, ' '); if ( end ) { *end = '\0'; relation = end + 1; end = strchr ( relation, ' '); if ( end ) { *end = '\0'; evr = end + 1; } for ( ; (*relation) != '\0'; relation++ ) { if ( (*relation) == '=' ) { sense_flags |= RPMSENSE_EQUAL; } else if ( (*relation) == '>' ) { sense_flags |= RPMSENSE_GREATER; } else if ( (*relation) == '<' ) { sense_flags |= RPMSENSE_LESS; } } } dep = rpm_require_new(name, rpm_version_new(evr), sense_flags, package_new_from_NEVR(p->pkgNEVR) ); free ( buf ); rb_ary_push(list, dep); } else { #if 0 RPMPROB_CONFLICT: RPMPROB_BADARCH: RPMPROB_BADOS: RPMPROB_PKG_INSTALLED: RPMPROB_BADRELOCATE: RPMPROB_NEW_FILE_CONFLICT: RPMPROB_FILE_CONFLICT: RPMPROB_OLDPACKAGE: RPMPROB_DISKSPACE: RPMPROB_DISKNODES: RPMPROB_BADPRETRANS: #endif break; } #if 0 printf ("%d, type=%d, ignoreProblem=%d, str1=%s pkgNEVR=%s, %s\n", i, p->type, p->ignoreProblem, p->str1, p->pkgNEVR, altNEVR); #endif } } #endif /* RPMPS_OPAQUE */ ps = rpmpsFree(ps); return list; #endif }
/* * Performs the transaction. * @param [Number] flag Transaction flags, default +RPM::TRANS_FLAG_NONE+ * @param [Number] filter Transaction filter, default +RPM::PROB_FILTER_NONE+ * @example * transaction.commit do |sig| * end * @yield [CallbackData] sig Transaction progress */ VALUE rpm_transaction_commit(int argc, VALUE* argv, VALUE trans) { #if RPM_VERSION_CODE < RPM_VERSION(4,1,0) rpmProblemSet probset; int flags = RPMTRANS_FLAG_NONE; int ignores = RPMPROB_FILTER_NONE; int rc; VALUE db; db = rb_ivar_get(trans, id_db); if (OBJ_FROZEN(db)) { rb_error_frozen("RPM::DB"); } switch (argc) { case 0: break; case 1: case 2: flags = NUM2INT(rb_Integer(argv[0])); if (argc == 2) { ignores = NUM2INT(rb_Integer(argv[1])); } break; default: rb_raise(rb_eArgError, "too many arguments(0..2)"); } if (rb_block_given_p() == Qtrue) rc = rpmRunTransactions(RPM_TRANSACTION(trans), transaction_callback, (void*)trans, NULL, &probset, flags, ignores); else{ VALUE keys; /* rpmcli.h:extern int packagesTotal; */ packagesTotal = 0; keys = rpm_transaction_keys(trans); if (!NIL_P(keys)) packagesTotal = NUM2INT(rb_funcall(keys,rb_intern("length"),0)); rc = rpmRunTransactions(RPM_TRANSACTION(trans), rpmShowProgress, (void*)((long)(INSTALL_HASH|INSTALL_LABEL)), NULL, &probset, flags, ignores); } if (probset != NULL) { VALUE list = rb_ary_new(); register int i; for (i = 0; i < probset->numProblems; i++) { rpmProblem prob = probset->probs + i; VALUE prb = rb_struct_new(rpm_sProblem, INT2NUM(prob->type), (VALUE)prob->key, rpm_package_new_from_header(prob->h), rb_str_new2(rpmProblemString(prob))); rb_ary_push(list, prb); } rb_ivar_set(trans, id_pl, list); } #else rpmps ps; int flags = RPMTRANS_FLAG_NONE; int ignores = RPMPROB_FILTER_NONE; int rc; VALUE db; db = rb_ivar_get(trans, id_db); if (OBJ_FROZEN(db)) { rb_error_frozen("RPM::DB"); } switch (argc) { case 0: break; case 1: case 2: flags = NUM2INT(rb_Integer(argv[0])); if (argc == 2) { ignores = NUM2INT(rb_Integer(argv[1])); } break; default: rb_raise(rb_eArgError, "too many arguments(0..2)"); } /* Drop added/available package indices and dependency sets. */ //rpmtsClean(RPM_TRANSACTION(trans)); // zaki: required? if (rb_block_given_p() == Qtrue) { rpmtsSetNotifyCallback(RPM_TRANSACTION(trans), (rpmCallbackFunction)transaction_callback,(void *)trans); }else{ VALUE keys; /* rpmcli.h:extern int rpmcliPackagesTotal; */ rpmcliPackagesTotal = 0; keys = rpm_transaction_keys(trans); if (!NIL_P(keys)) rpmcliPackagesTotal = NUM2INT(rb_funcall(keys,rb_intern("length"),0)); rpmtsSetNotifyCallback(RPM_TRANSACTION(trans), rpmShowProgress, (void*)((long)(INSTALL_HASH|INSTALL_LABEL))); } rc = rpmtsRun(RPM_TRANSACTION(trans), NULL, ignores); ps = rpmtsProblems(RPM_TRANSACTION(trans)); { VALUE list = rb_ary_new(); #ifdef RPMPS_OPAQUE rpmpsi psi = rpmpsInitIterator(ps); while (rpmpsNextIterator(psi) >= 0) { rpmProblem p = rpmpsGetProblem(psi); VALUE prb = rb_struct_new(rpm_sProblem, INT2NUM(rpmProblemGetType(p)), (VALUE)rpmProblemGetKey(p), package_new_from_NEVR( rpmProblemGetAltNEVR(p)+2 ), rb_str_new2(rpmProblemString(p))); rb_ary_push(list, prb); } #else if (ps != NULL && rpmpsNumProblems(ps) > 0) { register int i; for (i = 0; i < rpmpsNumProblems(ps); i++) { rpmProblem p = ps->probs + i; const char *altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?"); VALUE prb = rb_struct_new(rpm_sProblem, INT2NUM(p->type), (VALUE)p->key, package_new_from_NEVR(altNEVR+2), rb_str_new2(rpmProblemString(p))); rb_ary_push(list, prb); } } #endif rb_ivar_set(trans, id_pl, list); } if (ps) ps = rpmpsFree(ps); #endif rb_ivar_set(trans, id_commited, Qtrue); rb_throw("abort", Qnil); return Qnil; /* NOT REACHED */ }