Exemplo n.º 1
0
func (v VersionRelation) SatisfiedBy(ver version.Version) bool {
	vVer, err := version.Parse(v.Number)
	if err != nil {
		return false
	}

	q := version.Compare(ver, vVer)
	switch v.Operator {
	case ">=":
		return q >= 0
	case "<=":
		return q <= 0
	case ">>":
		return q > 0
	case "<<":
		return q < 0
	case "=":
		return q == 0
	}

	// XXX: WHAT THE SHIT
	return false
}
Exemplo n.º 2
0
func (can Candidates) ExplainSatisfies(arch dependency.Arch, possi dependency.Possibility) (bool, string, []control.BinaryIndex) {
	entries, ok := can[possi.Name]
	if !ok { // no known entries in the Index
		return false, fmt.Sprintf("Totally unknown package: %s", possi.Name), nil
	}

	if possi.Arch != nil {
		satisfied := false
		archEntries := []control.BinaryIndex{}
		for _, installable := range entries {
			if installable.Architecture.Is(possi.Arch) {
				archEntries = append(archEntries, installable)
				satisfied = true
			}
		}
		if !satisfied {
			return false, fmt.Sprintf(
				"Relation depends on multiarch arch %s-%s-%s. Not found",
				possi.Arch.ABI,
				possi.Arch.OS,
				possi.Arch.CPU,
			), nil
		}
		entries = archEntries
	}

	if possi.Version == nil {
		return true, "Relation exists, no version constraint", entries
	}

	// OK, so we have to play with versions now.
	vr := *possi.Version
	relatioNumber, _ := version.Parse(vr.Number)
	satisfied := false
	seenRealtions := []string{}

	versionEntries := []control.BinaryIndex{}
	for _, installable := range entries {
		q := version.Compare(installable.Version, relatioNumber)
		seenRealtions = append(seenRealtions, installable.Version.String())

		switch vr.Operator {
		case ">=":
			satisfied = q >= 0
		case "<=":
			satisfied = q <= 0
		case ">>":
			satisfied = q > 0
		case "<<":
			satisfied = q < 0
		case "=":
			satisfied = q == 0
		default:
			return false, "Unknown operator D:", nil // XXX: WHAT THE SHIT
		}

		if satisfied {
			versionEntries = append(versionEntries, installable)
		}
	}

	if len(versionEntries) > 0 {
		return true, "Relation exists with a satisfied version constraint", versionEntries
	}

	return false, fmt.Sprintf(
		"%s is version constrainted %s %s. Valid options: %s",
		possi.Name,
		vr.Operator,
		vr.Number,
		strings.Join(seenRealtions, ", "),
	), nil
}