packaging: github.com/juju/packaging/manager Index | Files | Directories

package manager

import "github.com/juju/packaging/manager"

The manager package defines an interface which can carry out numerous package-management related operations on the local system and the respective implementations on apt and yum-based systems.

Index

Package Files

apt.go interface.go manager.go snap.go utils.go yum.go zypper.go

Variables

var (
    AttemptStrategy = retry.Regular{
        Delay: 10 * time.Second,
        Min:   30,
    }
)
var CommandOutput = (*exec.Cmd).CombinedOutput

CommandOutput is cmd.Output. It was aliased for testing purposes.

var ProcessStateSys = (*os.ProcessState).Sys

processStateSys is ps.Sys. It was aliased for testing purposes.

var RunCommand = func(command string, args ...string) (output string, err error) {
    cmd := exec.Command(command, args...)
    out, err := cmd.CombinedOutput()
    output = string(out)
    if err != nil {
        return output, err
    }
    return output, nil
}

RunCommand is helper function to execute the command and gather the output.

var RunCommandWithRetry = func(cmd string, getFatalError func(string) error) (output string, code int, err error) {
    var out []byte

    args := strings.Fields(cmd)
    if len(args) <= 1 {
        return "", 1, errors.New(fmt.Sprintf("too few arguments: expected at least 2, got %d", len(args)))
    }

    logger.Infof("Running: %s", cmd)

    for a := AttemptStrategy.Start(nil); a.Next(); {

        command := exec.Command(args[0], args[1:]...)

        out, err = CommandOutput(command)

        if err == nil {
            return string(out), 0, nil
        }

        exitError, ok := err.(*exec.ExitError)
        if !ok {
            err = errors.Annotatef(err, "unexpected error type %T", err)
            break
        }
        waitStatus, ok := ProcessStateSys(exitError.ProcessState).(exitStatuser)
        if !ok {
            err = errors.Annotatef(err, "unexpected process state type %T", exitError.ProcessState.Sys())
            break
        }

        code = waitStatus.ExitStatus()
        if code != 100 {
            break
        }

        if getFatalError != nil {
            if fatalErr := getFatalError(string(out)); fatalErr != nil {
                err = errors.Annotatef(fatalErr, "encountered fatal error")
                break
            }
        }

        logger.Infof("Retrying: %s", cmd)
    }

    if err != nil {
        logger.Errorf("packaging command failed: %v; cmd: %q; output: %s",
            err, cmd, string(out))
        return string(out), code, errors.Errorf("packaging command failed: %v", err)
    }

    return string(out), 0, nil
}

RunCommandWithRetry is a helper function which tries to execute the given command. It tries to do so for 30 times with a 10 second sleep between commands. It returns the output of the command, the exit code, and an error, if one occurs, logging along the way. It was aliased for testing purposes.

type PackageManager Uses

type PackageManager interface {
    // InstallPrerequisite runs the command which installs the prerequisite
    // package which provides repository management functionalityes.
    InstallPrerequisite() error

    // Update runs the command to update the local package list.
    Update() error

    // Upgrade runs the command which issues an upgrade on all packages
    // with available newer versions.
    Upgrade() error

    // Install runs a *single* command that installs the given package(s).
    Install(packs ...string) error

    // Remove runs a *single* command that removes the given package(s).
    Remove(packs ...string) error

    // Purge runs the command that removes the given package(s) along
    // with any associated config files.
    Purge(packs ...string) error

    // Search runs the command that determines whether the given package is
    // available for installation from the currently configured repositories.
    Search(pack string) (bool, error)

    // IsInstalled runs the command which determines whether or not the
    // given package is currently installed on the system.
    IsInstalled(pack string) bool

    // AddRepository runs the command that adds a repository to the
    // list of available repositories.
    // NOTE: requires the prerequisite package whose installation command
    // is done by running InstallPrerequisite().
    AddRepository(repo string) error

    // RemoveRepository runs the command that removes a given
    // repository from the list of available repositories.
    // NOTE: requires the prerequisite package whose installation command
    // is done by running InstallPrerequisite().
    RemoveRepository(repo string) error

    // Cleanup runs the command that cleans up all orphaned packages,
    // left-over files and previously-cached packages.
    Cleanup() error

    // GetProxySettings returns the curretly-configured package manager proxy.
    GetProxySettings() (proxy.Settings, error)

    // SetProxy runs the commands to set the given proxy parameters for the
    // package management system.
    SetProxy(settings proxy.Settings) error
}

PackageManager is the interface which carries out various package-management related work.

func NewAptPackageManager Uses

func NewAptPackageManager() PackageManager

NewAptPackageManager returns a PackageManager for apt-based systems.

func NewPackageManager Uses

func NewPackageManager(series string) (PackageManager, error)

NewPackageManager returns the appropriate PackageManager implementation based on the provided series.

func NewYumPackageManager Uses

func NewYumPackageManager() PackageManager

NewYumPackageManager returns a PackageManager for yum-based systems.

func NewZypperPackageManager Uses

func NewZypperPackageManager() PackageManager

type Snap Uses

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

Snap is the PackageManager implementation for snap-based systems.

func NewSnapPackageManager Uses

func NewSnapPackageManager() *Snap

NewSnapPackageManager returns a PackageManager for snap-based systems.

func (*Snap) AddRepository Uses

func (pm *Snap) AddRepository(repo string) error

AddRepository is defined on the PackageManager interface.

func (*Snap) ChangeChannel Uses

func (snap *Snap) ChangeChannel(pack, channel string) error

ChangeChannel updates the tracked channel for an installed snap.

func (*Snap) Cleanup Uses

func (pm *Snap) Cleanup() error

Cleanup is defined on the PackageManager interface.

func (*Snap) ConfigureStoreProxy Uses

func (snap *Snap) ConfigureStoreProxy(assertions, storeID string) error

ConfigureStoreProxy sets up snapd to connect to the snap store proxy instance defined in the provided assertions using the provided store ID.

If snap also needs to use HTTP/HTTPS proxies to talk to the outside world, these need to be configured separately before invoking this method via a call to SetProxy.

func (*Snap) DisableStoreProxy Uses

func (snap *Snap) DisableStoreProxy() error

DisableStoreProxy resets the snapd proxy store settings.

If snap was also configured to use HTTP/HTTPS proxies these must be reset separately via a call to SetProxy. call to SetProxy.

func (*Snap) GetProxySettings Uses

func (snap *Snap) GetProxySettings() (proxy.Settings, error)

GetProxySettings is defined on the PackageManager interface.

func (*Snap) Install Uses

func (snap *Snap) Install(packs ...string) error

Install is defined on the PackageManager interface.

func (*Snap) InstallPrerequisite Uses

func (pm *Snap) InstallPrerequisite() error

InstallPrerequisite is defined on the PackageManager interface.

func (*Snap) InstalledChannel Uses

func (snap *Snap) InstalledChannel(pack string) string

InstalledChannel returns the snap channel for an installed package.

func (*Snap) IsInstalled Uses

func (snap *Snap) IsInstalled(pack string) bool

IsInstalled is defined on the PackageManager interface.

func (*Snap) Purge Uses

func (pm *Snap) Purge(packs ...string) error

Purge is defined on the PackageManager interface.

func (*Snap) Remove Uses

func (pm *Snap) Remove(packs ...string) error

Remove is defined on the PackageManager interface.

func (*Snap) RemoveRepository Uses

func (pm *Snap) RemoveRepository(repo string) error

RemoveRepository is defined on the PackageManager interface.

func (*Snap) Search Uses

func (snap *Snap) Search(pack string) (bool, error)

Search is defined on the PackageManager interface.

func (*Snap) SetProxy Uses

func (pm *Snap) SetProxy(settings proxy.Settings) error

SetProxy is defined on the PackageManager interface.

func (*Snap) Update Uses

func (pm *Snap) Update() error

Update is defined on the PackageManager interface.

func (*Snap) Upgrade Uses

func (pm *Snap) Upgrade() error

Upgrade is defined on the PackageManager interface.

Directories

PathSynopsis
testingThis package contains a mock implementation of the manager.PackageManager interface which always returns positive outcomes and a nil error.

Package manager imports 13 packages (graph) and is imported by 20 packages. Updated 2020-05-07. Refresh now. Tools for package owners.