Documentation
¶
Overview ¶
Package version parses PHP release versions and compares distribution package versions with each package manager's own rules (dpkg, apk, rpm).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareAPK ¶
CompareAPK compares two Alpine package versions (digit{.digit}...{letter}{_suffix{number}}...{~hash}{-rN}) and returns -1, 0 or 1.
It runs both apk-tools orderings, transcribed from the sources: apk-tools 3 (src/version.c of 3.0.x, used by Alpine 3.23 and later) and apk-tools 2 (src/version.c of 2.14.x, Alpine 3.22 and earlier). It returns an error when either version is invalid for either implementation (apk_version_validate), or when the two implementations order the pair differently, so a verdict never depends on which apk-tools generation a system runs. For every version Alpine actually ships (8.3.29-r0, 1.2.3_rc1-r2, 2.0_p1~abc123-r0 ...) the two agree.
func CompareDpkg ¶
CompareDpkg compares two Debian package versions with dpkg's ordering (Debian Policy 5.6.12, dpkg_version_compare): epoch numerically, then the upstream version and the revision with verrevcmp, where "~" sorts before everything including the end of the string, letters sort before other characters, and digit runs compare numerically. It returns -1, 0 or 1, or an error when either version is one dpkg rejects or warns about (see ParseDpkg).
func CompareRPM ¶
CompareRPM compares two EVR strings as rpm's rpmverCmp (rpm 4.18+, also what the Lua rpm.vercmp() and dnf use) does: epochs with rpmvercmp, a missing epoch counting as "0"; then versions; then releases, where a missing release sorts below any present one. It returns -1, 0 or 1.
func RPMVerCmp ¶
RPMVerCmp is rpm's rpmvercmp() (rpmio/rpmvercmp.c) on one version or release field: alphanumeric segments, separators ignored, "~" sorting before everything (also the end), "^" sorting after the end but before any other segment, numeric segments compared by value and above alphabetic ones. Bytes from a NUL on are ignored.
func ValidateAPK ¶
ValidateAPK reports whether apk-tools 2 and 3 both accept v as a version.
Types ¶
type DpkgVersion ¶
DpkgVersion is a parsed Debian package version: [epoch:]upstream[-revision].
func ParseDpkg ¶
func ParseDpkg(s string) (DpkgVersion, error)
ParseDpkg parses a Debian version exactly as dpkg's parseversion() (lib/dpkg/parsehelp.c) does, and rejects everything dpkg rejects or warns about:
- errors in dpkg: empty or blank string, embedded blanks, empty epoch, non-numeric, negative or too large (> INT_MAX) epoch, nothing after the colon, empty revision after a trailing hyphen, empty upstream version;
- warnings in dpkg ("has bad syntax" but still compared): upstream not starting with a digit, a character other than [A-Za-z0-9.+~:-] in the upstream version, or other than [A-Za-z0-9.+~] in the revision.
Warnings are treated as errors here on purpose: dpkg still orders such versions, but no archive ships them, and a verdict must not rest on a version dpkg itself calls malformed. Like dpkg, leading and trailing blanks (space, tab) are ignored and the epoch is read with strtol semantics, so "+1:2" and "01:2" both have epoch 1. A NUL byte is rejected (dpkg can never see one: C strings end there).
func (DpkgVersion) Compare ¶
func (v DpkgVersion) Compare(o DpkgVersion) int
Compare orders two parsed versions; -1, 0 or 1.
func (DpkgVersion) String ¶
func (v DpkgVersion) String() string
String formats the version the way dpkg writes it unambiguously: the epoch is omitted when zero unless the upstream version contains a colon.
type EVR ¶
type EVR struct {
// Epoch is the epoch as written; empty when absent. HasEpoch distinguishes
// "0:1.0" from "1.0" (rpm compares a missing epoch as "0", so they are
// equal).
Epoch string
HasEpoch bool
Version string
// Release is the text after the last hyphen; HasRelease is false when there
// is no hyphen.
Release string
HasRelease bool
}
EVR is an rpm [epoch:]version[-release], split the way rpm's parseEVR (rpmio/rpmver.c) splits it.
func ParseEVR ¶
ParseEVR splits an EVR string as rpm does: the epoch is a (possibly empty) run of leading digits followed by ':' (an empty epoch means "0"); the release is whatever follows the last '-' after the epoch. Anything else is the version. Like rpm, it never fails; bytes from a NUL on are ignored, as C never sees them.
type PHP ¶
type PHP struct {
Major, Minor, Patch int
// Pre is a pre-release or development tag ("RC1", "alpha2", "beta1", "dev"),
// empty for a release.
Pre string
// Extra is anything after the version and tag, as written.
Extra string
}
PHP is an upstream PHP version as PHP itself reports it in PHP_VERSION: MAJOR.MINOR.PATCH, optionally followed by a pre-release or development tag ("8.4.0RC1", "8.5.0alpha2", "8.6.0-dev") and PHP_EXTRA_VERSION, which some builders set ("-0ubuntu0.20.04.1" on old Ubuntu releases).
func ParsePHP ¶
ParsePHP parses a PHP_VERSION string. Strings that do not start with MAJOR.MINOR.PATCH are rejected: a branch alone ("8.3") is not a version.
func (PHP) CompareRelease ¶
CompareRelease compares the numeric MAJOR.MINOR.PATCH parts only.