yum

package module
v0.0.0-...-3b8baa9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

README

go-yum

Documentation

Index

Constants

View Source
const (
	LOG_CAT_ERROR = iota
	LOG_CAT_WARN
	LOG_CAT_INFO
	LOG_CAT_DEBUG
)

Variables

View Source
var (
	QuietMode       bool
	DebugMode       bool
	YumfilePath     string
	LogFilePath     string
	TmpBasePath     string
	TmpYumConfPath  string
	TmpYumLogFile   string
	TmpYumCachePath string
	DownloadThreads int
)
View Source
var ErrChecksumMismatch = fmt.Errorf("Checksum mismatch")

ErrChecksumMismatch indicates that the checksum value of two items does not match.

Functions

func CloseLogFile

func CloseLogFile()

CloseLogFile cleans up any file handles associates with the log file.

func Dprintf

func Dprintf(format string, a ...interface{})

Dprintf prints verbose output only if debug mode is enabled

func Errorf

func Errorf(err error, format string, a ...interface{})

Errorf prints an error message to log or STDOUT

func Fatalf

func Fatalf(err error, format string, a ...interface{})

Fatalf prints an error message to log or STDOUT and exits the program with a non-zero exit code

func InitLogFile

func InitLogFile()

func Logf

func Logf(category int, format string, a ...interface{})

Logf prints output to a logfile with a category and timestamp

func NewErrorf

func NewErrorf(format string, a ...interface{}) error

func OpenKeyRing

func OpenKeyRing(path string) (openpgp.KeyRing, error)

OpenKeyRing returns the GPG keyring for the given gpgkey file.

func PanicOn

func PanicOn(err error)

func Printf

func Printf(format string, a ...interface{})

Printf prints output to STDOUT or the logfile

func ValidateChecksum

func ValidateChecksum(r io.Reader, checksum string, checksum_type string) error

ValidateChecksum creates a checksum of the given io.Reader content and compares it the the given checksum value. If the checksums match, nil is returned. If the checksums do not match, ErrChecksumMismatch is returned. If any other error occurs, the error is returned.

func ValidateFileChecksum

func ValidateFileChecksum(name string, checksum string, checksum_type string) error

ValidateChecksum creates a checksum of the given file content and compares it the the given checksum value. If the checksums match, nil is returned. If the checksums do not match, ErrChecksumMismatch is returned. If any other error occurs, the error is returned.

Types

type Cache

type Cache struct {
	Path string
}

func NewCache

func NewCache(path string) (*Cache, error)

func (*Cache) NewRepoCache

func (c *Cache) NewRepoCache(repo *Repo) (*RepoCache, error)

type Collection

type Collection struct {
	Short    string     `xml:"short,attr"`
	Name     string     `xml:"name"`
	Packages []*Package `xml:"package"`
}

type Package

type Package struct {
	Name     string `xml:"name,attr"`
	Version  string `xml:"version,attr"`
	Release  string `xml:"release,attr"`
	Epoch    int    `xml:"epoch,attr"`
	Arch     string `xml:"arch,attr"`
	Src      string `xml:"src,attr"`
	FileName string `xml:"filename"`
}

type PackageEntries

type PackageEntries []PackageEntry

PackageEntries is a slice of PackageEntry structs.

func FilterPackages

func FilterPackages(repo *Repo, packages PackageEntries) PackageEntries

FilterPackages returns a list of packages filtered according the repo's settings.

type PackageEntry

type PackageEntry struct {
	Key         int
	Arch        string               `xml:"arch"`
	Size        PackageEntrySize     `xml:"size"`
	Checksums   PackageEntryChecksum `xml:"checksum"`
	Location    PackageEntryLocation `xml:"location"`
	PackageName string               `xml:"name"`
	Versions    PackageEntryVersion  `xml:"version"`
	Time        PackageEntryTime     `xml:"time"`
	Summary     string               `xml:"summary"`
	Url         string               `xml:"url"`
	Packager    string               `xml:"packager"`
	// contains filtered or unexported fields
}

PackageEntry is a RPM package as defined in a yum repository database.

func (*PackageEntry) Architecture

func (c *PackageEntry) Architecture() string

func (*PackageEntry) ArchiveSize

func (c *PackageEntry) ArchiveSize() int64

func (*PackageEntry) BuildTime

func (c *PackageEntry) BuildTime() time.Time

func (*PackageEntry) Checksum

func (c *PackageEntry) Checksum() (string, error)

func (*PackageEntry) ChecksumType

func (c *PackageEntry) ChecksumType() string

func (*PackageEntry) Epoch

func (c *PackageEntry) Epoch() int

func (*PackageEntry) InstallSize

func (c *PackageEntry) InstallSize() int64

func (*PackageEntry) LocationHref

func (c *PackageEntry) LocationHref() string

LocationHref is the location of the package, relative to the parent repository.

func (*PackageEntry) Name

func (c *PackageEntry) Name() string

func (*PackageEntry) PackageSize

func (c *PackageEntry) PackageSize() int64

func (*PackageEntry) Release

func (c *PackageEntry) Release() string

func (PackageEntry) String

func (c PackageEntry) String() string

String reassembles package metadata to form a standard rpm package name; including the package name, version, release and architecture.

func (*PackageEntry) Version

func (c *PackageEntry) Version() string

type PackageEntryChecksum

type PackageEntryChecksum struct {
	Type  string `xml:"type,attr"`
	Pkgid string `xml:"pkgid,attr"`
	Hash  string `xml:",chardata"`
}

PackageEntryChecksum is the XML element of a package metadata file which describes the checksum required to validate a package.

type PackageEntryLocation

type PackageEntryLocation struct {
	Href string `xml:"href,attr"`
}

RepoDatabaseLocation represents the URI, relative to a package repository, of a repository database.

type PackageEntrySize

type PackageEntrySize struct {
	Package   int64 `xml:"type,attr"`
	Installed int64 `xml:"installed,attr"`
	Archive   int64 `xml:"archive,attr"`
}

type PackageEntryTime

type PackageEntryTime struct {
	File  int64 `xml:"file,attr"`
	Build int64 `xml:"build,attr"`
}

PackageEntryChecksum is the XML element of a package metadata file which describes the checksum required to validate a package.

type PackageEntryVersion

type PackageEntryVersion struct {
	Epoch   int    `xml:"epoch,attr"`
	Version string `xml:"ver,attr"`
	Release string `xml:"rel,attr"`
}

type PkgList

type PkgList struct {
	Collection *Collection `xml:"collection"`
}

type PrimaryDatabase

type PrimaryDatabase struct {
	// contains filtered or unexported fields
}

PrimaryDatabase is an SQLite database which contains package data for a yum package repository.

func CreatePrimaryDB

func CreatePrimaryDB(path string) (*PrimaryDatabase, error)

CreatePrimaryDB initializes a new and empty primary_db SQLite database on disk. Any existing path is deleted.

func OpenPrimaryDB

func OpenPrimaryDB(path string) (*PrimaryDatabase, error)

OpenPrimaryDB opens a primary_db SQLite database from file and return a pointer to the resulting struct.

func (*PrimaryDatabase) Begin

func (c *PrimaryDatabase) Begin() (*sql.Tx, error)

func (*PrimaryDatabase) Close

func (c *PrimaryDatabase) Close() error

func (*PrimaryDatabase) DependenciesByPackage

func (c *PrimaryDatabase) DependenciesByPackage(pkgKey int, typ string) (rpm.Dependencies, error)

DependenciesByPackage returns all package dependencies of the given type for the given package key. The dependency type may be one of 'requires', 'provides', 'conflicts' or 'obsoletes'.

func (*PrimaryDatabase) FilesByPackage

func (c *PrimaryDatabase) FilesByPackage(pkgKey int) ([]string, error)

FilesByPackage returns all known files included in the package of the given package key.

func (*PrimaryDatabase) InsertPackage

func (c *PrimaryDatabase) InsertPackage(packages ...*rpm.PackageFile) error

func (*PrimaryDatabase) Packages

func (c *PrimaryDatabase) Packages() (PackageEntries, error)

Packages returns all packages listed in the primary_db.

type PrimaryDatabaseWriter

type PrimaryDatabaseWriter chan<- *rpm.PackageFile

PrimaryDatabaseWriter writes packages to a Primary Database. It is the callers responsibility to close the channel when all packages have been sent.

func (PrimaryDatabaseWriter) Close

func (w PrimaryDatabaseWriter) Close()

func (PrimaryDatabaseWriter) Write

func (w PrimaryDatabaseWriter) Write(p *rpm.PackageFile)

type PrimaryMetadata

type PrimaryMetadata struct {
	XMLName       xml.Name `xml:"metadata"`
	XMLNS         string   `xml:"xmlns,attr"`
	PackagesCount int      `xml:"packages,attr"`

	Packages PackageEntries `xml:"package"`
}

PrimaryMetadata represents the metadata XML file for a RPM/Yum repository. It contains packages available in the repository.

func ReadPrimaryMetadata

func ReadPrimaryMetadata(r io.Reader) (*PrimaryMetadata, error)

ReadPrimaryMetadata loads a primary.xml file from the given io.Reader and returns a pointer to the resulting PrimaryMetadata struct.

type Reference

type Reference struct {
	Href  string `xml:"href,attr"`
	ID    string `xml:"id,attr"`
	Type  string `xml:"type,attr"`
	Title string `xml:"title,attr"`
}

type ReferenceCollection

type ReferenceCollection struct {
	References []*Reference `xml:"reference"`
}

type Repo

type Repo struct {
	ID             string
	Name           string
	Architecture   string
	BaseURL        string
	CachePath      string
	Checksum       string
	DeleteRemoved  bool
	GPGCheck       bool
	GPGKey         string
	Groupfile      string
	IncludeSources bool
	LocalPath      string
	MirrorURL      string
	NewOnly        bool
	MaxDate        time.Time
	MinDate        time.Time
	YumfileLineNo  int
	YumfilePath    string
}

Repo is a package repository defined in a Yumfile

func NewRepo

func NewRepo() *Repo

NewRepo initializes a new Repo struct and returns a pointer to it.

func (*Repo) CacheLocal

func (c *Repo) CacheLocal(path string) (*RepoCache, error)

CacheLocal caches a copy of a Repo's metadata and databases to the given cache directory. If the Repo is already cached, the cache is validated and updated if the source repository has been updated.

func (Repo) String

func (c Repo) String() string

func (*Repo) Sync

func (c *Repo) Sync(cachedir, packagedir string) error

Sync syncronizes a local package repository with an upstream repository using filter rules defined for the repository in its parent Yumfile. All repository metadata is cached in the given cache directory.

func (*Repo) Validate

func (c *Repo) Validate() error

Validate checks the syntax of a repo defined in a Yumfile and returns an on the first syntax error encountered. If no errors are found, nil is returned.

type RepoCache

type RepoCache struct {
	Repo *Repo
	Path string
}

func (*RepoCache) PrimaryDB

func (c *RepoCache) PrimaryDB() (*PrimaryDatabase, error)

func (*RepoCache) Update

func (c *RepoCache) Update(databases ...string) error

func (*RepoCache) UpdateInfoDB

func (c *RepoCache) UpdateInfoDB() (*UpdateInfoDatabase, error)

type RepoDatabase

type RepoDatabase struct {
	Type            string               `xml:"type,attr"`
	Location        RepoDatabaseLocation `xml:"location"`
	Timestamp       int                  `xml:"timestamp"`
	Size            int                  `xml:"size"`
	Checksum        RepoDatabaseChecksum `xml:"checksum"`
	OpenSize        int                  `xml:"open-size"`
	OpenChecksum    RepoDatabaseChecksum `xml:"open-checksum"`
	DatabaseVersion int                  `xml:"database_version"`
}

RepoDatabase represents an entry in a repository metadata file for an individual database file such as primary_db or filelists_db.

func (*RepoDatabase) String

func (c *RepoDatabase) String() string

type RepoDatabaseChecksum

type RepoDatabaseChecksum struct {
	Type string `xml:"type,attr"`
	Hash string `xml:",chardata"`
}

RepoDatabaseChecksum is the XML element of a repo metadata file which describes the checksum required to validate a repository database.

func (*RepoDatabaseChecksum) Check

func (c *RepoDatabaseChecksum) Check(r io.Reader) error

Check creates a checksum of the given io.Reader content and compares it the the expected checksum value. If the checksums match, nil is returned. If the checksums do not match, ErrChecksumMismatch is returned. If any other error occurs, the error is returned.

func (*RepoDatabaseChecksum) CheckFile

func (c *RepoDatabaseChecksum) CheckFile(name string) error

CheckFile creates a checksum of the given file content and compares it the the expected checksum value. If the checksums match, nil is returned. If the checksums do not match, ErrChecksumMismatch is returned. If any other error occurs, the error is returned.

type RepoDatabaseLocation

type RepoDatabaseLocation struct {
	Href string `xml:"href,attr"`
}

RepoDatabaseLocation represents the URI, relative to a package repository, of a repository database.

type RepoMetadata

type RepoMetadata struct {
	XMLName  xml.Name `xml:"repomd"`
	XMLNS    string   `xml:"xmlns,attr"`
	XMLNSRPM string   `xml:"xmlns:rpm,attr"`

	Revision  int            `xml:"revision"`
	Databases []RepoDatabase `xml:"data"`
}

RepoMetadata represents the metadata XML file for a RPM/Yum repository. It contains pointers to database files which describe the packages available in the repository.

func ReadRepoMetadata

func ReadRepoMetadata(r io.Reader) (*RepoMetadata, error)

ReadRepoMetadata loads a repomd.xml file from the given io.Reader and returns a pointer to the resulting RepoMetadata struct.

func (*RepoMetadata) Write

func (c *RepoMetadata) Write(w io.Writer) error

Write encodes a RepoMetadata struct in the repomd.xml format to the given io.Writer stream.

type UpdateInfo

type UpdateInfo struct {
	XMLName       xml.Name        `xml:"updates"`
	UpdateNotices []*UpdateNotice `xml:"update"`
}

type UpdateInfoDatabase

type UpdateInfoDatabase struct {
	// contains filtered or unexported fields
}

func OpenUpdateInfoDB

func OpenUpdateInfoDB(path string) (*UpdateInfoDatabase, error)

func (*UpdateInfoDatabase) UpdateNotices

func (u *UpdateInfoDatabase) UpdateNotices() ([]*UpdateNotice, error)

type UpdateInfoTime

type UpdateInfoTime struct {
	Date string `xml:"date,attr"`
	Time int64  `xml:"time,attr"`
}

type UpdateNotice

type UpdateNotice struct {
	Author      string               `xml:"author,attr"`
	From        string               `xml:"from,attr"`
	Status      string               `xml:"status,attr"`
	Type        string               `xml:"type,attr"`
	Version     string               `xml:"version,attr"`
	ID          string               `xml:"id"`
	Title       string               `xml:"title"`
	Issued      *UpdateInfoTime      `xml:"issued"`
	Updated     *UpdateInfoTime      `xml:"updated"`
	Rights      string               `xml:"rights"`
	Release     string               `xml:"release"`
	Severity    string               `xml:"severity"`
	Summary     string               `xml:"summary"`
	Description string               `xml:"description"`
	References  *ReferenceCollection `xml:"references"`
	PkgList     *PkgList             `xml:"pkglist"`
}

func (*UpdateNotice) UpdatedTime

func (u *UpdateNotice) UpdatedTime() time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL