{
if DpkgInstanced {
return errors.New("another dpkg instance already exists")
}
C.dpkg_program_init(C.CString("a.out"))
C.modstatdb_open(C.msdbrw_available_readonly)
DpkgInstanced = true
return nil
}
{
if !DpkgInstanced {
return errors.New("no dpkg instance exists")
}
C.dpkg_program_done()
DpkgInstanced = false
return nil
}
{
pkgInfo := C.pkg_hash_find_singleton(C.CString(pkgName))
version := C.GoString(C.versiondescribe(&pkgInfo.configversion, C.vdew_nonambig))
if version == "<none>" {
version = ""
}
return version
}
{
NewDpkgInstance()
version := getPackageVersion(pkgName)
DpkgDispose()
return version
}
{
versions := make([]string, len(pkgNames))
NewDpkgInstance()
for i := 0; i < len(pkgNames); i++ {
versions[i] = getPackageVersion(pkgNames[i])
}
DpkgDispose()
return versions
}
{
version := DpkgGetPackageVersion("git")
fmt.Printf("Version: %s\n", version)
if version != "1:2.40.1-1" {
t.Fail()
}
}
{
versions := DpkgBatchGetPackageVersion([]string{"git", "golang"})
fmt.Printf("Versions: %v\n", versions)
if versions[0] != "1:2.40.1-1" || versions[1] != "2:1.21~2" {
t.Fail()
}
}
import "C"
import "errors"
import "fmt"
import "testing"