lib

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AptErrorPackageNotFound   = 21
	AptErrorInvalidParameters = 91
)

APT error codes (must match apt_error.h)

Variables

View Source
var AptMutex sync.Mutex

AptMutex is the global mutex for all apt-lib operations

View Source
var T_ = func(msgid string) string { return msgid }

T_ is the string translation hook, defaults to identity

Functions

func BeginLogCapture

func BeginLogCapture(handler LogHandler) (stop func())

BeginLogCapture starts capturing APT output into handler, returns a stop function.

func BeginOperation

func BeginOperation()

BeginOperation blocks signals and marks an active APT operation

func CaptureStdIO

func CaptureStdIO(enable bool)

CaptureStdIO manually enables/disables stdout/stderr capture

func CheckLockOrError

func CheckLockOrError() error

CheckLockOrError checks if APT/RPM is locked and returns an error if it is.

func ClearInstallArguments

func ClearInstallArguments()

ClearInstallArguments clears the arguments

func ConfigRestore

func ConfigRestore(snapshot unsafe.Pointer)

ConfigRestore restores APT configuration from the snapshot (frees it).

func ConfigSnapshot

func ConfigSnapshot() unsafe.Pointer

ConfigSnapshot creates a copy of the whole APT configuration tree.

func DumpConfig

func DumpConfig() string

DumpConfig returns the whole APT configuration as a string.

func EndOperation

func EndOperation()

EndOperation unmarks the operation and restores signals

func PreprocessInstallArguments

func PreprocessInstallArguments(names []string) error

PreprocessInstallArguments registers arguments in APT config before opening the cache

func RegisterSignalChannel

func RegisterSignalChannel(ch chan os.Signal)

RegisterSignalChannel registers the signal channel to restore after APT operations

func SetConfig

func SetConfig(key, value string)

SetConfig sets an APT config value (e.g. "Dir::Cache::Archives", "/tmp/")

func SetLogHandler

func SetLogHandler(handler LogHandler)

SetLogHandler intercepts stdout/stderr via LogHandler

func SetNoLocking

func SetNoLocking(noLock bool)

SetNoLocking enables or disables APT file locking.

func SetTranslator

func SetTranslator(fn func(msgid string) string)

SetTranslator sets the translation function

func WaitIdle

func WaitIdle()

WaitIdle waits for all APT operations to finish

func WithConfigOverrides

func WithConfigOverrides(overrides map[string]string, fn func() error) error

WithConfigOverrides snapshots the configuration, applies overrides, runs fn, then restores the snapshot.

Types

type AptError

type AptError struct {
	Code    int
	Message string
}

func CustomError

func CustomError(code int, message string) *AptError

func ErrorFromResult

func ErrorFromResult(res C.AptResult) *AptError

ErrorFromResult converts C.AptResult to Go error and frees message

func (*AptError) Error

func (e *AptError) Error() string

func (e *AptError) Error() string { return fmt.Sprintf("APT Error %d: %s", e.Code, e.Message) }

type Cache

type Cache struct {
	Ptr *C.AptCache
	// contains filtered or unexported fields
}

Cache represents package cache

func OpenCache

func OpenCache(system *System, readOnly bool) (*Cache, error)

OpenCache opens the package cache

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) DownloadSource added in v0.5.2

func (c *Cache) DownloadSource(names []string, destDir string, handler ProgressHandler) ([]SourcePackage, error)

DownloadSource downloads .src.rpm files for the given names into destDir

func (*Cache) GetPackageInfo

func (c *Cache) GetPackageInfo(packageName string) (*PackageInfo, error)

func (*Cache) NewTransaction

func (c *Cache) NewTransaction() (*Transaction, error)

NewTransaction creates a new transaction for the cache

func (*Cache) Refresh

func (c *Cache) Refresh() error

func (*Cache) SearchPackages

func (c *Cache) SearchPackages(pattern string) ([]PackageInfo, error)

func (*Cache) SimulateAutoRemove

func (c *Cache) SimulateAutoRemove() (*PackageChanges, error)

SimulateAutoRemove simulates removal of unused packages

func (*Cache) SimulateChange

func (c *Cache) SimulateChange(installNames []string, removeNames []string, purge bool, depends bool) (*PackageChanges, error)

SimulateChange simulates install and remove in a single transaction

func (*Cache) SimulateChangeWithRpmInfo

func (c *Cache) SimulateChangeWithRpmInfo(installNames []string, removeNames []string, purge bool, depends bool, rpmFiles []string) (*PackageChanges, []*PackageInfo, error)

SimulateChangeWithRpmInfo simulates changes and fetches RPM file info in a single cache session

func (*Cache) SimulateDistUpgrade

func (c *Cache) SimulateDistUpgrade() (*PackageChanges, error)

SimulateDistUpgrade simulates a system upgrade

func (*Cache) SimulateInstall

func (c *Cache) SimulateInstall(packageNames []string) (*PackageChanges, error)

SimulateInstall simulates package installation

func (*Cache) SimulateReinstall

func (c *Cache) SimulateReinstall(packageNames []string) (*PackageChanges, error)

SimulateReinstall simulates package reinstallation

func (*Cache) SimulateRemove

func (c *Cache) SimulateRemove(packageNames []string, purge bool, depends bool) (*PackageChanges, error)

SimulateRemove simulates package removal

func (*Cache) Update

func (c *Cache) Update(handler ProgressHandler) error

type ErrLocked

type ErrLocked struct {
	Status LockStatus
}

ErrLocked is returned when APT/RPM is locked by another process

func (*ErrLocked) Error

func (e *ErrLocked) Error() string

type EssentialPackage

type EssentialPackage struct {
	Name   string `json:"name"`
	Reason string `json:"reason"`
}

EssentialPackage represents an essential/important package that will be removed

type LockStatus

type LockStatus struct {
	IsLocked     bool
	CanAcquire   bool
	LockPID      int
	LockHolder   string
	LockFilePath string
	ErrorMessage string
}

LockStatus represents the status of APT/RPM locks

func CheckLockStatus

func CheckLockStatus() LockStatus

CheckLockStatus checks if APT locks can be acquired without actually acquiring them.

type LogHandler

type LogHandler func(message string)

type PackageChanges

type PackageChanges struct {
	ExtraInstalled       []string `json:"extraInstalled"`
	UpgradedPackages     []string `json:"upgradedPackages"`
	NewInstalledPackages []string `json:"newInstalledPackages"`
	RemovedPackages      []string `json:"removedPackages"`
	KeptBackPackages     []string `json:"keptBackPackages"`

	UpgradedCount     int `json:"upgradedCount"`
	NewInstalledCount int `json:"newInstalledCount"`
	RemovedCount      int `json:"removedCount"`
	KeptBackCount     int `json:"keptBackCount"`
	NotUpgradedCount  int `json:"notUpgradedCount"`

	DownloadSize uint64 `json:"downloadSize"`
	InstallSize  int64  `json:"installSize"`

	EssentialPackages []EssentialPackage `json:"essentialPackages"`
}

PackageChanges represents the changes that would occur during package ops

type PackageInfo

type PackageInfo struct {
	Name             string
	Version          string
	Description      string
	ShortDescription string
	Section          string
	Architecture     string
	Maintainer       string
	Homepage         string
	Priority         string
	MD5Hash          string
	Blake2bHash      string
	SourcePackage    string
	Changelog        string
	Filename         string
	Depends          string
	Provides         string
	Conflicts        string
	Obsoletes        string
	Recommends       string
	Suggests         string
	State            PackageState
	AutoInstalled    bool
	Essential        bool
	InstalledSize    uint64
	DownloadSize     uint64
	PackageID        uint32
	Aliases          []string
	Files            []string
}

type PackageState

type PackageState int
const (
	//	PackageStateNotInstalled    PackageState = 0
	PackageStateInstalled PackageState = 1
)

Package states (must match AptPackageState in apt_common.h)

type ProgressHandler

type ProgressHandler func(packageName string, eventType ProgressType, current, total, speed uint64)

type ProgressType

type ProgressType int
const (
	CallbackInstallProgress      ProgressType = 1
	CallbackDownloadStart        ProgressType = 20
	CallbackDownloadProgress     ProgressType = 21
	CallbackDownloadStop         ProgressType = 22
	CallbackDownloadComplete     ProgressType = 23
	CallbackDownloadItemProgress ProgressType = 24
)

type SourcePackage added in v0.5.2

type SourcePackage struct {
	Name    string
	Version string
	File    string
	Size    uint64
}

SourcePackage describes a downloaded source package (.src.rpm)

type System

type System struct{ Ptr *C.AptSystem }

System represents the APT system configuration

func NewSystem

func NewSystem() (*System, error)

NewSystem initializes the APT system

func (*System) Close

func (s *System) Close()

Close releases system resources

type Transaction

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

Transaction encapsulates the lifecycle of a package operation

func (*Transaction) AutoRemove

func (tx *Transaction) AutoRemove() error

AutoRemove marks the transaction as removal of unused packages

func (*Transaction) Close

func (tx *Transaction) Close()

Close releases transaction resources

func (*Transaction) DistUpgrade

func (tx *Transaction) DistUpgrade() error

DistUpgrade marks the transaction as a system upgrade

func (*Transaction) Execute

func (tx *Transaction) Execute(handler ProgressHandler, downloadOnly bool) error

Execute executes the transaction

func (*Transaction) Install

func (tx *Transaction) Install(names []string) error

Install adds packages to install

func (*Transaction) Plan

func (tx *Transaction) Plan() (*PackageChanges, error)

Plan simulates the transaction

func (*Transaction) Reinstall

func (tx *Transaction) Reinstall(names []string) error

Reinstall adds packages to reinstall

func (*Transaction) Remove

func (tx *Transaction) Remove(names []string, purge, depends bool) error

Remove adds packages to remove

Jump to

Keyboard shortcuts

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