NewDpkgInstance function

Returns:

  • error
Show/Hide Function Body
{
	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
}

DpkgDispose function

Returns:

  • error
Show/Hide Function Body
{
	if !DpkgInstanced {
		return errors.New("no dpkg instance exists")
	}

	C.dpkg_program_done()

	DpkgInstanced = false
	return nil
}

getPackageVersion function

Parameters:

  • pkgName string

Returns:

  • string
Show/Hide Function Body
{
	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
}

DpkgGetPackageVersion function

Parameters:

  • pkgName string

Returns:

  • string
Show/Hide Function Body
{
	NewDpkgInstance()
	version := getPackageVersion(pkgName)
	DpkgDispose()

	return version
}

DpkgBatchGetPackageVersion function

Parameters:

  • pkgNames []string

Returns:

  • []string
Show/Hide Function Body
{
	versions := make([]string, len(pkgNames))

	NewDpkgInstance()
	for i := 0; i < len(pkgNames); i++ {
		versions[i] = getPackageVersion(pkgNames[i])
	}
	DpkgDispose()

	return versions
}

TestGetPackageVersion function

Parameters:

  • t *testing.T
Show/Hide Function Body
{
	version := DpkgGetPackageVersion("git")
	fmt.Printf("Version: %s\n", version)

	if version != "1:2.40.1-1" {
		t.Fail()
	}
}

TestBatchGetPackageVersion function

Parameters:

  • t *testing.T
Show/Hide Function Body
{
	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()
	}
}

C import

Import example:

import "C"

errors import

Import example:

import "errors"

fmt import

Import example:

import "fmt"

testing import

Import example:

import "testing"