Esempio n. 1
0
int
doCheck(PTDNFRPMTS pTS)
{
  int nResult = 0;
  rpmpsi psi = NULL;
  rpmProblem prob = NULL;
  nResult = rpmtsCheck(pTS->pTS);

  rpmps ps = rpmtsProblems(pTS->pTS);
  if(ps)
  {
    int nProbs = rpmpsNumProblems(ps);
    if(nProbs > 0)
    {
      printf("Found %d problems\n", nProbs);

      psi = rpmpsInitIterator(ps);
      while(rpmpsNextIterator(psi) >= 0)
      {
        prob = rpmpsGetProblem(psi);
        printf("Prob = %s, type = %d, nevr1=%s, nevr2=%s\n",
            rpmProblemGetStr(prob),
            rpmProblemGetType(prob),
            rpmProblemGetPkgNEVR(prob),
            rpmProblemGetAltNEVR(prob));
        rpmProblemFree(prob);
      }
      rpmpsFreeIterator(psi);
    }
  }
  return nResult;
}
Esempio n. 2
0
/**
 * Check installed package dependencies for problems.
 * @param qva		parsed query/verify options
 * @param ts		transaction set
 * @param h		header
 * @return		number of problems found (0 for no problems)
 */
static int verifyDependencies(/*@unused@*/ QVA_t qva, rpmts ts,
		Header h)
	/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
	/*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/
{
#ifdef	NOTYET
    uint32_t hdrNum = headerGetInstance(h);
#endif
    rpmps ps;
    int rc = 0;		/* assume no problems */
    int xx;

    rpmtsEmpty(ts);

#ifdef	NOTYET
    if (hdrNum > 0)
	(void) rpmtsAddEraseElement(ts, h, hdrNum);
    else
#endif
	(void) rpmtsAddInstallElement(ts, h, headerGetOrigin(h), 0, NULL);

    xx = rpmtsCheck(ts);
    ps = rpmtsProblems(ts);

    if (rpmpsNumProblems(ps) > 0) {
	const char * altNEVR;
	const char * pkgNEVR = NULL;
	rpmpsi psi;
	rpmProblem prob;
	char * t, * te;
	int nb = 512;

	psi = rpmpsInitIterator(ps);
	while (rpmpsNextIterator(psi) >= 0) {
	    prob = rpmpsProblem(psi);
	    if (pkgNEVR == NULL)
		pkgNEVR = rpmProblemGetPkgNEVR(prob);

	    altNEVR = rpmProblemGetAltNEVR(prob);
assert(altNEVR != NULL);
	    if (altNEVR[0] == 'R' && altNEVR[1] == ' ')
		nb += sizeof("\tRequires: ")-1;
	    if (altNEVR[0] == 'C' && altNEVR[1] == ' ')
		nb += sizeof("\tConflicts: ")-1;
	    nb += strlen(altNEVR+2) + sizeof("\n") - 1;

	}
	psi = rpmpsFreeIterator(psi);

	te = t = alloca(nb);
	*te = '\0';
	sprintf(te, _("Unsatisfied dependencies for %s:\n"), pkgNEVR);
	te += strlen(te);

	psi = rpmpsInitIterator(ps);
	while (rpmpsNextIterator(psi) >= 0) {
	    prob = rpmpsProblem(psi);

	    if ((altNEVR = rpmProblemGetAltNEVR(prob)) == NULL)
		altNEVR = "? ?altNEVR?";
	    if (altNEVR[0] == 'R' && altNEVR[1] == ' ')
		te = stpcpy(te, "\tRequires: ");
	    if (altNEVR[0] == 'C' && altNEVR[1] == ' ')
		te = stpcpy(te, "\tConflicts: ");
	    te = stpcpy( stpcpy(te, altNEVR+2), "\n");

	    rc++;
	}
	psi = rpmpsFreeIterator(psi);

	if (te > t) {
	    *te++ = '\n';
	    *te = '\0';
	    rpmlog(RPMLOG_NOTICE, "%s", t);
	    te = t;
	    *t = '\0';
	}
    }

    ps = rpmpsFree(ps);

    rpmtsEmpty(ts);

    return rc;
}
Esempio n. 3
0
static PyObject *rpmprob_get_altnevr(rpmProblemObject *s, void *closure)
{
    return Py_BuildValue("s", rpmProblemGetAltNEVR(s->prob));
}
Esempio n. 4
0
/*
 * 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
}
Esempio n. 5
0
/*
 * 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 */
}