Skip to content

pombredanne/dpkgcomp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DpkgComp Coverage GoDoc

About

This Go library compares Debian-like package version numbers. For instance, it can tell that version 1:1.25-4 is lower than 1:1.25-8.

The implementation is based on http://man.he.net/man5/deb-version and on https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version. The algorithm is inspired from dpkg-1.17.25 (lib/version.c and lib/parsehelp.c).

Installing

Installing this library is easy-peasy, as usual.

go get github.com/quentin-m/dpkgcomp

You could also run tests

go test github.com/quentin-m/dpkgcomp

Usage

Will you be able to guess the ouput ?

package main

import (
	"log"

	"github.com/quentin-m/dpkgcomp"
)
func main() {
	// Define our version numbers
	v1 := "0:1.18.36-a"
	v2 := "1.18.36"

    // Compare our versions
	cmp, err := dpkgcomp.Compare(v1, v2)
	if err != nil {
		log.Fatalln(err)
	}
	if cmp == 0 {
		log.Println(v1, "is equal to", v2)
	} else if cmp == 1 {
		log.Println(v1, "is higher than", v2)
	} else {
		log.Println(v1, "is lower than", v2)
	}
}

About

Go library - Compares Debian-like package version numbers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%