Categorygithub.com/cavaliergopher/rpm
modulepackage
1.2.0
Repository: https://github.com/cavaliergopher/rpm.git
Documentation: pkg.go.dev

# README

rpm

Go Reference Build Status Go Report Card

Package rpm implements the rpm package file format.

$ go get github.com/cavaliergopher/rpm

See the package documentation or the examples programs in cmd/ to get started.

Extracting rpm packages

The following working example demonstrates how to extract files from an rpm package. In this example, only the cpio format and xz compression are supported which will cover most cases.

Implementations should consider additional formats and compressions algorithms, as well as support for extracting irregular file types and configuring permissions, uids and guids, etc.

package main

import (
	"io"
	"log"
	"os"
	"path/filepath"

	"github.com/cavaliergopher/cpio"
	"github.com/cavaliergopher/rpm"
	"github.com/ulikunitz/xz"
)

func ExtractRPM(name string) {
	// Open a package file for reading
	f, err := os.Open(name)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// Read the package headers
	pkg, err := rpm.Read(f)
	if err != nil {
		log.Fatal(err)
	}

	// Check the compression algorithm of the payload
	if compression := pkg.PayloadCompression(); compression != "xz" {
		log.Fatalf("Unsupported compression: %s", compression)
	}

	// Attach a reader to decompress the payload
	xzReader, err := xz.NewReader(f)
	if err != nil {
		log.Fatal(err)
	}

	// Check the archive format of the payload
	if format := pkg.PayloadFormat(); format != "cpio" {
		log.Fatalf("Unsupported payload format: %s", format)
	}

	// Attach a reader to unarchive each file in the payload
	cpioReader := cpio.NewReader(xzReader)
	for {
		// Move to the next file in the archive
		hdr, err := cpioReader.Next()
		if err == io.EOF {
			break // no more files
		}
		if err != nil {
			log.Fatal(err)
		}

		// Skip directories and other irregular file types in this example
		if !hdr.Mode.IsRegular() {
			continue
		}

		// Create the target directory
		if dirName := filepath.Dir(hdr.Name); dirName != "" {
			if err := os.MkdirAll(dirName, 0o755); err != nil {
				log.Fatal(err)
			}
		}

		// Create and write the file
		outFile, err := os.Create(hdr.Name)
		if err != nil {
			log.Fatal(err)
		}
		if _, err := io.Copy(outFile, cpioReader); err != nil {
			outFile.Close()
			log.Fatal(err)
		}
		outFile.Close()
	}
}

# Packages

No description provided by the author

# Functions

Compare compares the version details of two packages.
CompareVersion compares version strings.
GPGCheck validates the integrity of an rpm package file.
MD5Check validates the integrity of an rpm package file.
Open opens an rpm package from the file system.
KeyRingFromFiles reads a openpgp.KeyRing from the given file paths which may then be used to validate GPG keys in rpm packages.
Read reads an rpm package from r.
ReadKeyRing reads a openpgp.KeyRing from the given io.Reader which may then be used to validate GPG keys in rpm packages.
Sort sorts a slice of packages lexically by name ascending and then by version descending.

# Constants

Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
Dependency flags indicate how versions comparisons should be computed when comparing versions of dependent packages.
%%artifact.
%%config.
%%doc.
%%ghost.
%%donotuse.
%%license.
%%config(missingok).
File flags make up some attributes of files depending on how they were specified in the rpmspec.
%%config(noreplace).
%%pubkey.
%%readme.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TimeFormat is the time format used by the rpm ecosystem.

# Variables

ErrGPGCheckFailed indicates that an rpm package failed GPG signature validation.
ErrMD5CheckFailed indicates that an rpm package failed MD5 checksum validation.
ErrNotRPMFile indicates that the file is not an rpm package.

# Structs

A FileInfo describes a file in an rpm package.
A Header stores metadata about an rpm package.
Lead is the deprecated lead section of an rpm file which is used in legacy rpm versions to store package metadata.
A Package is an rpm package file.
Tag is an rpm header entry and its associated data value.

# Interfaces

Dependency is an interface which represents a relationship between two packages.
Version is an interface which holds version information for a package in EVR form.

# Type aliases

GPGSignature is the raw byte representation of a package's signature.
PackageSlice implements sort.Interface for a slice of packages.
TagType describes the data type of a tag's value.