Documentation ¶
Overview ¶
Package rpm provides a native implementation of the RPM file specification.
package main import ( "fmt" "github.com/jfrog/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
- type Dependency
- type FileInfo
- func (f *FileInfo) Digest() string
- func (f *FileInfo) Flags() int64
- func (f *FileInfo) Group() string
- func (f *FileInfo) IsDir() bool
- func (f *FileInfo) Linkname() string
- 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 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) Enhances() []Dependency
- 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) 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) Recommends() []Dependency
- 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) Suggests() []Dependency
- func (c *PackageFile) Summary() string
- func (c *PackageFile) Supplements() []Dependency
- func (c *PackageFile) URL() string
- func (c *PackageFile) Vendor() string
- func (c *PackageFile) Version() string
- func (c *PackageFile) XPMImage() []byte
- type Time
Examples ¶
Constants ¶
const ( DepFlagAny = 0 DepFlagLesser = (1 << 1) DepFlagGreater = (1 << 2) DepFlagEqual = (1 << 3) DepFlagLesserOrEqual = (DepFlagEqual | DepFlagLesser) DepFlagGreaterOrEqual = (DepFlagEqual | DepFlagGreater) DepFlagPrereq = (1 << 6) DepFlagScriptPre = (1 << 9) DepFlagScriptPost = (1 << 10) DepFlagScriptPreUn = (1 << 11) DepFlagScriptPostUn = (1 << 12) DepFlagRpmlib = (1 << 24) )
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
const ( FileFlagNone = 0 FileFlagConfig = (1 << 0) // %%config FileFlagDoc = (1 << 1) // %%doc FileFlagIcon = (1 << 2) // %%donotuse FileFlagMissingOk = (1 << 3) // %%config(missingok) FileFlagNoReplace = (1 << 4) // %%config(noreplace) FileFlagGhost = (1 << 6) // %%ghost FileFlagLicense = (1 << 7) // %%license FileFlagReadme = (1 << 8) // %%readme FileFlagPubkey = (1 << 11) // %%pubkey FileFlagArtifact = (1 << 12) // %%artifact )
File flags make up some attributes of files depending on how they were specified in the rpmspec
const ( IndexDataTypeNull int = iota IndexDataTypeChar IndexDataTypeInt8 IndexDataTypeInt16 IndexDataTypeInt32 IndexDataTypeInt64 IndexDataTypeString IndexDataTypeBinary IndexDataTypeStringArray IndexDataTypeI8NString )
Header index value data types.
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 = errors.New("RPM header section is incorrect length") // ErrNotHeader indicates that the read header section does start with the // expected descriptor. ErrNotHeader = errors.New("invalid RPM header descriptor") // ErrBadIndexCount indicates that number of indexes given in the read // header would exceed the actual size of the header. ErrBadIndexCount = errors.New("index count exceeds header size") // ErrIndexOutOfRange indicates that the read header index would exceed the // range of the header. ErrIndexOutOfRange = errors.New("index is out of range") // ErrBadIndexType indicates that the read index contains a value of an // unsupported data type. ErrBadIndexType = errors.New("unknown index data type") // ErrBadIndexValueCount indicates that the read index value would exceed // the range of the header store section. ErrBadIndexValueCount = errors.New("index value count is out of range") )
var ( // 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") )
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.
// read public key from gpgkey file keyring, err := rpm.KeyRingFromFile("testdata/RPM-GPG-KEY-CentOS-7") if err != nil { panic(err) } // open a rpm package for reading f, err := os.Open("testdata/centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm") if err != nil { panic(err) } defer f.Close() // validate gpg signature if signer, err := rpm.GPGCheck(f, keyring); err == nil { fmt.Printf("Package signed by '%s'\n", signer) } else if err == rpm.ErrGPGValidationFailed { fmt.Printf("Package failed GPG signature validation\n") } else { panic(err) }
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.
// open a rpm package for reading f, err := os.Open("testdata/centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm") if err != nil { panic(err) } defer f.Close() // validate md5 checksum if err := rpm.MD5Check(f); err == nil { fmt.Printf("Package passed checksum validation\n") } else if err == rpm.ErrMD5ValidationFailed { fmt.Printf("Package failed checksum validation\n") } else { panic(err) }
Output: Package passed checksum validation
Types ¶
type Dependency ¶
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 Header ¶
type Header struct { Version int IndexCount int Length int Indexes IndexEntries }
A Header stores metadata about a rpm package.
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) Enhances ¶
func (c *PackageFile) Enhances() []Dependency
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.
// open a package file pkg, err := rpm.OpenPackageFile("./testdata/epel-release-7-5.noarch.rpm") if err != nil { panic(err) } // list each file files := pkg.Files() fmt.Printf("total %v\n", len(files)) for _, fi := range files { fmt.Printf("%v %v %v %5v %v %v\n", fi.Mode().Perm(), fi.Owner(), fi.Group(), fi.Size(), fi.ModTime().UTC().Format("Jan 02 15:04"), fi.Name()) }
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) 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) Recommends ¶
func (c *PackageFile) Recommends() []Dependency
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) Suggests ¶
func (c *PackageFile) Suggests() []Dependency
func (*PackageFile) Summary ¶
func (c *PackageFile) Summary() string
func (*PackageFile) Supplements ¶
func (c *PackageFile) Supplements() []Dependency
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