README
¶
go-rpm

A native implementation of the RPM file specification in Go.
$ go get github.com/cavaliercoder/go-rpm
The go-rpm package aims to enable cross-platform tooling for yum/dnf/rpm written in Go (E.g. y10k).
Initial goals include like-for-like implementation of existing rpm ecosystem features such as:
- Reading of modern and legacy rpm package file formats
- Reading, creating and updating modern and legacy yum repository metadata
- Reading of the rpm database
package main
import (
"fmt"
"github.com/cavaliercoder/go-rpm"
)
func main() {
p, err := rpm.OpenPackageFile("golang-1.6.3-2.el7.rpm")
if err != nil {
panic(err)
}
fmt.Printf("Loaded package: %v - %s\n", p, p.Summary())
// Output: golang-0:1.6.3-2.el7.x86_64 - The Go Programming Language
}
Tools
This package also includes two tools rpmdump
and rpminfo
.
The code for both tools demonstrates some use-cases of this package. They are both also useful for interrogating RPM packages on any platform.
$ rpminfo golang-1.6.3-2.el7.x86_64.rpm
Name : golang
Version : 1.6.3
Release : 2.el7
Architecture: x86_64
Group : Unspecified
Size : 11809071
License : BSD and Public Domain
Signature : RSA/SHA256, Sun Nov 20 18:01:16 2016, Key ID 24c6a8a7f4a80eb5
Source RPM : golang-1.6.3-2.el7.src.rpm
Build Date : Tue Nov 15 12:20:30 2016
Build Host : c1bm.rdu2.centos.org
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://golang.org/
Summary : The Go Programming Language
Description :
The Go Programming Language.
Documentation
¶
Overview ¶
Package rpm provides a native implementation of the RPM file specification.
package main import ( "fmt" "github.com/cavaliercoder/go-rpm" ) func main() { p, err := rpm.OpenPackageFile("my-package.rpm") if err != nil { panic(err) } fmt.Printf("Loaded package: %v", p) }
Index ¶
- Constants
- Variables
- func GPGCheck(r io.Reader, keyring openpgp.KeyRing) (string, error)
- func KeyRing(r io.Reader) (openpgp.KeyRing, error)
- func KeyRingFromFile(path string) (openpgp.KeyRing, error)
- func KeyRingFromFiles(files []string) (openpgp.KeyRing, error)
- func MD5Check(r io.Reader) error
- func VersionCompare(a PackageVersion, b PackageVersion) int
- type Dependency
- type FileInfo
- func (f *FileInfo) Group() string
- func (f *FileInfo) IsDir() bool
- func (f *FileInfo) ModTime() time.Time
- func (f *FileInfo) Mode() os.FileMode
- func (f *FileInfo) Name() string
- func (f *FileInfo) Owner() string
- func (f *FileInfo) Size() int64
- func (f *FileInfo) String() string
- func (f *FileInfo) Sys() interface{}
- type GPGSignature
- type Header
- type Headers
- type IndexEntries
- func (c IndexEntries) BytesByTag(tag int) []byte
- func (c IndexEntries) IndexByTag(tag int) *IndexEntry
- func (c IndexEntries) IntByTag(tag int) int64
- func (c IndexEntries) IntsByTag(tag int) []int64
- func (c IndexEntries) StringByTag(tag int) string
- func (c IndexEntries) StringsByTag(tag int) []string
- func (c IndexEntries) TimeByTag(tag int) time.Time
- func (c IndexEntries) TimesByTag(tag int) []time.Time
- type IndexEntry
- type Lead
- type PackageFile
- func (c *PackageFile) Architecture() string
- func (c *PackageFile) ArchiveSize() uint64
- func (c *PackageFile) BuildHost() string
- func (c *PackageFile) BuildTime() time.Time
- func (c *PackageFile) ChangeLog() []string
- func (c *PackageFile) Checksum() (string, error)
- func (c *PackageFile) ChecksumType() string
- func (c *PackageFile) Conflicts() []Dependency
- func (c *PackageFile) Description() string
- func (c *PackageFile) Distribution() string
- func (c *PackageFile) Epoch() int
- func (c *PackageFile) FileSize() uint64
- func (c *PackageFile) FileTime() time.Time
- func (c *PackageFile) Files() []FileInfo
- func (c *PackageFile) GIFImage() []byte
- func (c *PackageFile) GPGSignature() GPGSignature
- func (c *PackageFile) GetBytes(header, tag int) []byte
- func (c *PackageFile) GetInt(header, tag int) int64
- func (c *PackageFile) GetInts(header, tag int) []int64
- func (c *PackageFile) GetString(header, tag int) string
- func (c *PackageFile) GetStrings(header, tag int) []string
- func (c *PackageFile) Groups() []string
- func (c *PackageFile) HeaderEnd() uint64
- func (c *PackageFile) HeaderStart() uint64
- func (c *PackageFile) Icon() []byte
- func (c *PackageFile) InstallTime() time.Time
- func (c *PackageFile) License() string
- func (c *PackageFile) Name() string
- func (c *PackageFile) Obsoletes() []Dependency
- func (c *PackageFile) OldFilenames() []string
- func (c *PackageFile) OperatingSystem() string
- func (c *PackageFile) Packager() string
- func (c *PackageFile) Patch() []string
- func (c *PackageFile) Path() string
- func (c *PackageFile) PayloadCompression() string
- func (c *PackageFile) PayloadFormat() string
- func (c *PackageFile) Platform() string
- func (c *PackageFile) PostInstallScript() string
- func (c *PackageFile) PostUninstallScript() string
- func (c *PackageFile) PreInstallScript() string
- func (c *PackageFile) PreUninstallScript() string
- func (c *PackageFile) Provides() []Dependency
- func (c *PackageFile) RPMVersion() string
- func (c *PackageFile) Release() string
- func (c *PackageFile) Requires() []Dependency
- func (c *PackageFile) Size() uint64
- func (c *PackageFile) Source() []string
- func (c *PackageFile) SourceRPM() string
- func (c *PackageFile) String() string
- func (c *PackageFile) Summary() string
- func (c *PackageFile) URL() string
- func (c *PackageFile) Vendor() string
- func (c *PackageFile) Version() string
- func (c *PackageFile) XPMImage() []byte
- type PackageVersion
- type Time
Examples ¶
Constants ¶
const ( DepFlagAny = 0 DepFlagLesser = (1 << 1) DepFlagGreater = (1 << 2) DepFlagEqual = (1 << 3) DepFlagLesserOrEqual = (DepFlagEqual | DepFlagLesser) DepFlagGreaterOrEqual = (DepFlagEqual | DepFlagGreater) )
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
const ( IndexDataTypeNull int = iota IndexDataTypeChar IndexDataTypeInt8 IndexDataTypeInt16 IndexDataTypeInt32 IndexDataTypeInt64 IndexDataTypeString IndexDataTypeBinary IndexDataTypeStringArray IndexDataTypeI8NString )
Header index value data types.
const (
// MAX_HEADER_SIZE is the maximum allowable header size in bytes (32 MB).
MAX_HEADER_SIZE = 33554432
)
Predefined sizing constraints.
const RPMDate = "Mon Jan _2 15:04:05 2006"
RPMDate is the Time format used by rpm tools.
Variables ¶
var ( // ErrMD5ValidationFailed indicates that a RPM package failed checksum // validation. ErrMD5ValidationFailed = fmt.Errorf("MD5 checksum validation failed") // ErrGPGValidationFailed indicates that a RPM package failed GPG signature // validation. ErrGPGValidationFailed = fmt.Errorf("GPG signature validation failed") // ErrGPGUnknownSignature indicates that the RPM package signature tag is of // an unknown type. ErrGPGUnknownSignature = fmt.Errorf("unknown signature type") )
Predefined checksum errors.
var ( // ErrBadHeaderLength indicates that the read header section is not the // expected length. ErrBadHeaderLength = fmt.Errorf("RPM header section is incorrect length") // ErrNotHeader indicates that the read header section does start with the // expected descriptor. ErrNotHeader = fmt.Errorf("invalid RPM header descriptor") // ErrBadStoreLength indicates that the read header store section is not the // expected length. ErrBadStoreLength = fmt.Errorf("header value store is incorrect length") )
Predefined header errors.
var ( // ErrBadIndexCount indicates that number of indexes given in the read // header would exceed the actual size of the header. ErrBadIndexCount = fmt.Errorf("index count exceeds header size") // ErrBadIndexLength indicates that the read header index section is not the // expected length. ErrBadIndexLength = fmt.Errorf("index section is incorrect length") // ErrIndexOutOfRange indicates that the read header index would exceed the // range of the header. ErrIndexOutOfRange = fmt.Errorf("index is out of range") // ErrBadIndexType indicates that the read index contains a value of an // unsupported data type. ErrBadIndexType = fmt.Errorf("unknown index data type") // ErrBadIndexValueCount indicates that the read index value would exceed // the range of the header store section. ErrBadIndexValueCount = fmt.Errorf("index value count is out of range") )
Predefined header index errors.
var ( // ErrBadLeadLength indicates that the read lead section is not the expected // length. ErrBadLeadLength = fmt.Errorf("RPM lead section is incorrect length") // ErrNotRPMFile indicates that the read file does not start with the // expected descriptor. ErrNotRPMFile = fmt.Errorf("RPM file descriptor is invalid") // ErrUnsupportedVersion indicates that the read lead section version is not // currently supported. ErrUnsupportedVersion = fmt.Errorf("unsupported RPM package version") )
Predefined lead section errors.
Functions ¶
func GPGCheck ¶
GPGCheck validates the integrity of a RPM package file read from the given io.Reader. Public keys in the given keyring are used to validate the package signature.
If validation succeeds, nil is returned. If validation fails, ErrGPGValidationFailed is returned.
This function is an expensive operation which reads the entire package file.
Example ¶
ExampleGPGCheck reads a public GPG key and uses it to validate the signature of a local rpm package.
Output: Package signed by 'CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>'
func KeyRing ¶
KeyRing reads a openpgp.KeyRing from the given io.Reader which may then be used to validate GPG keys in RPM packages.
func KeyRingFromFile ¶
KeyRingFromFile reads a openpgp.KeyRing from the given file path which may then be used to validate GPG keys in RPM packages.
func KeyRingFromFiles ¶
KeyRingFromFiles reads a openpgp.KeyRing from the given file paths which may then be used to validate GPG keys in RPM packages.
This function might typically be used to read all keys in /etc/pki/rpm-gpg.
func MD5Check ¶
MD5Check validates the integrity of a RPM package file read from the given io.Reader. An MD5 checksum is computed for the package payload and compared with the checksum value specified in the package header.
If validation succeeds, nil is returned. If validation fails, ErrMD5ValidationFailed is returned.
This function is an expensive operation which reads the entire package file.
Example ¶
ExampleMD5Check validates a local rpm package named using the MD5 checksum value specified in the package header.
Output: Package passed checksum validation
func VersionCompare ¶
func VersionCompare(a PackageVersion, b PackageVersion) int
VersionCompare compares the version details of two packages. Versions are compared by Epoch, Version and Release in descending order of precedence.
If a is more recent than b, 1 is returned. If a is less recent than b, -1 is returned. If a and b are equal, 0 is returned.
This function does not consider if the two packages have the same name or if either package has been made obsolete by the other.
Example ¶
ExampleVersionCompare reads packages in a directory and prints the name of the package with the highest version.
Output: Latest package: centos-release-5-0.0.el5.centos.2.i386
Types ¶
type Dependency ¶
type Dependency interface { PackageVersion // DepFlag constants Flags() int }
Dependency is an interface which represents a relationship between two packages. It might indicate that one package requires, conflicts with, obsoletes or provides another package.
Dependency implements the PackageVersion interface and so may be used when comparing versions with other types of packages.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
A FileInfo describes a file in a RPM package and is returned by packagefile.Files.
FileInfo implements the os.FileInfo interface.
type GPGSignature ¶
type GPGSignature []byte
GPGSignature is the raw byte representation of a package's signature.
func (GPGSignature) String ¶
func (b GPGSignature) String() string
type IndexEntries ¶
type IndexEntries []IndexEntry
IndexEntries is an array of IndexEntry structs.
func (IndexEntries) BytesByTag ¶
func (c IndexEntries) BytesByTag(tag int) []byte
BytesByTag returns the raw value of an IndexEntry or nil if the tag is not found or has no value.
func (IndexEntries) IndexByTag ¶
func (c IndexEntries) IndexByTag(tag int) *IndexEntry
IndexByTag returns a pointer to an IndexEntry with the given tag ID or nil if the tag is not found.
func (IndexEntries) IntByTag ¶
func (c IndexEntries) IntByTag(tag int) int64
IntByTag returns the int64 value of an IndexEntry or 0 if the tag is not found or has no value. Values with a lower range (E.g. int8) are cast as an int64.
func (IndexEntries) IntsByTag ¶
func (c IndexEntries) IntsByTag(tag int) []int64
IntsByTag returns the int64 values of an IndexEntry or nil if the tag is not found or has no value. Values with a lower range (E.g. int8) are cast as an int64.
func (IndexEntries) StringByTag ¶
func (c IndexEntries) StringByTag(tag int) string
StringByTag returns the string value of an IndexEntry or an empty string if the tag is not found or has no value.
func (IndexEntries) StringsByTag ¶
func (c IndexEntries) StringsByTag(tag int) []string
StringsByTag returns the slice of string values of an IndexEntry or nil if the tag is not found or has no value.
func (IndexEntries) TimeByTag ¶
func (c IndexEntries) TimeByTag(tag int) time.Time
TimeByTag returns the value of an IndexEntry as a Go native timestamp or zero-time if the tag is not found or has no value.
func (IndexEntries) TimesByTag ¶
func (c IndexEntries) TimesByTag(tag int) []time.Time
TimesByTag returns the value of an IndexEntry as a slice of Go native timestamps or nil if the tag is not found or has no value.
type IndexEntry ¶
An IndexEntry is a rpm key/value tag stored in the package header.
type Lead ¶
type Lead struct { VersionMajor int VersionMinor int Name string Type int Architecture int OperatingSystem int SignatureType int }
A Lead is the deprecated lead section of an RPM file which is used in legacy RPM versions to store package metadata.
type PackageFile ¶
A PackageFile is an RPM package definition loaded directly from the package file itself.
func OpenPackageFile ¶
func OpenPackageFile(path string) (*PackageFile, error)
OpenPackageFile reads a rpm package from the file system or a URL and returns a pointer to it.
func OpenPackageFiles ¶
func OpenPackageFiles(path string) ([]*PackageFile, error)
OpenPackageFiles reads all rpm packages with the .rpm suffix from the given directory on the file systems and returns a slice of pointers to the loaded packages.
func ReadPackageFile ¶
func ReadPackageFile(r io.Reader) (*PackageFile, error)
ReadPackageFile reads a rpm package file from a stream and returns a pointer to it.
func (*PackageFile) Architecture ¶
func (c *PackageFile) Architecture() string
func (*PackageFile) ArchiveSize ¶
func (c *PackageFile) ArchiveSize() uint64
ArchiveSize specifies the size of the archived payload of the package in bytes.
func (*PackageFile) BuildHost ¶
func (c *PackageFile) BuildHost() string
func (*PackageFile) BuildTime ¶
func (c *PackageFile) BuildTime() time.Time
func (*PackageFile) ChangeLog ¶
func (c *PackageFile) ChangeLog() []string
func (*PackageFile) Checksum ¶
func (c *PackageFile) Checksum() (string, error)
Checksum computes and returns the SHA256 checksum (encoded in hexadecimal) of the package file.
Checksum is a convenience function for tools that make use of package file SHA256 checksums. These might include many of the databases files created by the createrepo tool.
Checksum reopens the package using the file path that was given via OpenPackageFile. If the package was opened with any other method, Checksum will return "File not found".
func (*PackageFile) ChecksumType ¶
func (c *PackageFile) ChecksumType() string
ChecksumType returns "sha256"
func (*PackageFile) Conflicts ¶
func (c *PackageFile) Conflicts() []Dependency
func (*PackageFile) Description ¶
func (c *PackageFile) Description() string
func (*PackageFile) Distribution ¶
func (c *PackageFile) Distribution() string
func (*PackageFile) Epoch ¶
func (c *PackageFile) Epoch() int
func (*PackageFile) FileSize ¶
func (c *PackageFile) FileSize() uint64
FileSize returns the size of the package file in bytes if it was opened with OpenPackageFile.
func (*PackageFile) FileTime ¶
func (c *PackageFile) FileTime() time.Time
FileTime returns the time at which the RPM package file was last modified if it was opened with OpenPackageFile.
func (*PackageFile) Files ¶
func (c *PackageFile) Files() []FileInfo
Files returns file information for each file that is installed by this RPM package.
Example ¶
Lists all the files in a RPM package.
Output: total 7 -rw-r--r-- root root 1662 Nov 25 16:23 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 -rw-r--r-- root root 1056 Nov 25 16:23 /etc/yum.repos.d/epel-testing.repo -rw-r--r-- root root 957 Nov 25 16:23 /etc/yum.repos.d/epel.repo -rw-r--r-- root root 41 Nov 25 16:23 /usr/lib/rpm/macros.d/macros.epel -rw-r--r-- root root 2813 Nov 25 16:23 /usr/lib/systemd/system-preset/90-epel.preset -rwxr-xr-x root root 4096 Nov 25 16:26 /usr/share/doc/epel-release-7 -rw-r--r-- root root 18385 Nov 25 16:23 /usr/share/doc/epel-release-7/GPL
func (*PackageFile) GIFImage ¶
func (c *PackageFile) GIFImage() []byte
func (*PackageFile) GPGSignature ¶
func (c *PackageFile) GPGSignature() GPGSignature
func (*PackageFile) GetBytes ¶
func (c *PackageFile) GetBytes(header, tag int) []byte
GetBytes returns the value of the given tag in the given header. Nil is returned if the header or tag do not exist, or it the tag exists but is a different type.
func (*PackageFile) GetInt ¶
func (c *PackageFile) GetInt(header, tag int) int64
GetInt returns the int64 value of the given tag in the given header. Zero is returned if the header or tag do not exist, or if the tag exists but is a different type.
func (*PackageFile) GetInts ¶
func (c *PackageFile) GetInts(header, tag int) []int64
GetInts returns the int64 values of the given tag in the given header. Nil is returned if the header or tag do not exist, or if the tag exists but is a different type.
func (*PackageFile) GetString ¶
func (c *PackageFile) GetString(header, tag int) string
GetString returns the string value of the given tag in the given header. Nil is returned if the header or tag do not exist, or if the tag exists but is a different type.
func (*PackageFile) GetStrings ¶
func (c *PackageFile) GetStrings(header, tag int) []string
GetStrings returns the string values of the given tag in the given header. Nil is returned if the header or tag do not exist, or if the tag exists but is a different type.
func (*PackageFile) Groups ¶
func (c *PackageFile) Groups() []string
func (*PackageFile) HeaderEnd ¶
func (c *PackageFile) HeaderEnd() uint64
func (*PackageFile) HeaderStart ¶
func (c *PackageFile) HeaderStart() uint64
func (*PackageFile) Icon ¶
func (c *PackageFile) Icon() []byte
func (*PackageFile) InstallTime ¶
func (c *PackageFile) InstallTime() time.Time
func (*PackageFile) License ¶
func (c *PackageFile) License() string
func (*PackageFile) Name ¶
func (c *PackageFile) Name() string
func (*PackageFile) Obsoletes ¶
func (c *PackageFile) Obsoletes() []Dependency
func (*PackageFile) OldFilenames ¶
func (c *PackageFile) OldFilenames() []string
func (*PackageFile) OperatingSystem ¶
func (c *PackageFile) OperatingSystem() string
func (*PackageFile) Packager ¶
func (c *PackageFile) Packager() string
func (*PackageFile) Patch ¶
func (c *PackageFile) Patch() []string
func (*PackageFile) Path ¶
func (c *PackageFile) Path() string
Path returns the path which was given to open a package file if it was opened with OpenPackageFile.
func (*PackageFile) PayloadCompression ¶
func (c *PackageFile) PayloadCompression() string
PayloadCompression returns the name of the compression used for the package payload. Typically xz.
func (*PackageFile) PayloadFormat ¶
func (c *PackageFile) PayloadFormat() string
PayloadFormat returns the name of the format used for the package payload. Typically cpio.
func (*PackageFile) Platform ¶
func (c *PackageFile) Platform() string
func (*PackageFile) PostInstallScript ¶
func (c *PackageFile) PostInstallScript() string
func (*PackageFile) PostUninstallScript ¶
func (c *PackageFile) PostUninstallScript() string
func (*PackageFile) PreInstallScript ¶
func (c *PackageFile) PreInstallScript() string
func (*PackageFile) PreUninstallScript ¶
func (c *PackageFile) PreUninstallScript() string
func (*PackageFile) Provides ¶
func (c *PackageFile) Provides() []Dependency
func (*PackageFile) RPMVersion ¶
func (c *PackageFile) RPMVersion() string
func (*PackageFile) Release ¶
func (c *PackageFile) Release() string
func (*PackageFile) Requires ¶
func (c *PackageFile) Requires() []Dependency
func (*PackageFile) Size ¶
func (c *PackageFile) Size() uint64
Size specifies the disk space consumed by installation of the package.
func (*PackageFile) Source ¶
func (c *PackageFile) Source() []string
func (*PackageFile) SourceRPM ¶
func (c *PackageFile) SourceRPM() string
func (*PackageFile) String ¶
func (c *PackageFile) String() string
String returns the package identifier in the form '[name]-[version]-[release].[architecture]'.
func (*PackageFile) Summary ¶
func (c *PackageFile) Summary() string
func (*PackageFile) URL ¶
func (c *PackageFile) URL() string
func (*PackageFile) Vendor ¶
func (c *PackageFile) Vendor() string
func (*PackageFile) Version ¶
func (c *PackageFile) Version() string
func (*PackageFile) XPMImage ¶
func (c *PackageFile) XPMImage() []byte
type PackageVersion ¶
PackageVersion is an interface which holds version information for a single package.