snapstate

package
v0.0.0-...-b918686 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2016 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package snapstate implements the manager and state aspects responsible for the installation and removal of snaps.

Package snapstate implements the manager and state aspects responsible for the installation and removal of snaps.

Index

Constants

View Source
const (
	// DevMode switches confinement to non-enforcing mode.
	DevMode = 1 << iota
	// TryMode is set for snaps installed to try directly from a local directory.
	TryMode

	// JailMode is set when the user has requested confinement
	// always be enforcing, even if the snap requests otherwise.
	JailMode
)

Variables

View Source
var ErrNoCurrent = errors.New("snap has no current revision")

Functions

func ActiveInfos

func ActiveInfos(s *state.State) ([]*snap.Info, error)

ActiveInfos returns information about all active snaps.

func All

func All(s *state.State) (map[string]*SnapState, error)

All retrieves return a map from name to SnapState for all current snaps in the system state.

func CurrentInfo

func CurrentInfo(s *state.State, name string) (*snap.Info, error)

CurrentInfo returns the information about the current revision of a snap with the given name.

func Disable

func Disable(s *state.State, name string) (*state.TaskSet, error)

Disable sets a snap to the inactive state

func Enable

func Enable(s *state.State, name string) (*state.TaskSet, error)

Enable sets a snap to the active state

func GadgetInfo

func GadgetInfo(s *state.State) (*snap.Info, error)

GadgetInfo finds the current gadget snap's info.

func Get

func Get(s *state.State, name string, snapst *SnapState) error

Get retrieves the SnapState of the given snap.

func Info

func Info(s *state.State, name string, revision snap.Revision) (*snap.Info, error)

Info returns the information about the snap with given name and revision. Works also for a mounted candidate snap in the process of being installed.

func Install

func Install(s *state.State, name, channel string, userID int, flags Flags) (*state.TaskSet, error)

Install returns a set of tasks for installing snap. Note that the state must be locked by the caller.

func InstallPath

func InstallPath(s *state.State, name, path, channel string, flags Flags) (*state.TaskSet, error)

InstallPath returns a set of tasks for installing snap from a file path. Note that the state must be locked by the caller.

func Remove

func Remove(s *state.State, name string) (*state.TaskSet, error)

Remove returns a set of tasks for removing snap. Note that the state must be locked by the caller.

func ReplaceStore

func ReplaceStore(state *state.State, store StoreService)

ReplaceStore replaces the store used by the manager.

func Revert

func Revert(s *state.State, name string) (*state.TaskSet, error)

Revert returns a set of tasks for reverting to the pervious version of the snap. Note that the state must be locked by the caller.

func RevertToRevision

func RevertToRevision(s *state.State, name string, rev snap.Revision) (*state.TaskSet, error)

func Set

func Set(s *state.State, name string, snapst *SnapState)

Set sets the SnapState of the given snap, overwriting any earlier state.

func TryPath

func TryPath(s *state.State, name, path string, flags Flags) (*state.TaskSet, error)

TryPath returns a set of tasks for trying a snap from a file path. Note that the state must be locked by the caller.

func Update

func Update(s *state.State, name, channel string, userID int, flags Flags) (*state.TaskSet, error)

Update initiates a change updating a snap. Note that the state must be locked by the caller.

Types

type Flags

type Flags int

Flags are used to pass additional flags to operations and to keep track of snap modes.

func (Flags) DevMode

func (f Flags) DevMode() bool

func (Flags) DevModeAllowed

func (f Flags) DevModeAllowed() bool

func (Flags) JailMode

func (f Flags) JailMode() bool

type SnapManager

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

SnapManager is responsible for the installation and removal of snaps.

func Manager

func Manager(s *state.State) (*SnapManager, error)

Manager returns a new snap manager.

func (*SnapManager) Ensure

func (m *SnapManager) Ensure() error

Ensure implements StateManager.Ensure.

func (*SnapManager) Stop

func (m *SnapManager) Stop()

Stop implements StateManager.Stop.

func (*SnapManager) Wait

func (m *SnapManager) Wait()

Wait implements StateManager.Wait.

type SnapSetup

type SnapSetup struct {
	// FIXME: rename to RequestedChannel to convey the meaning better
	Channel string `json:"channel,omitempty"`
	UserID  int    `json:"user-id,omitempty"`

	Flags SnapSetupFlags `json:"flags,omitempty"`

	SnapPath string `json:"snap-path,omitempty"`

	DownloadInfo *snap.DownloadInfo `json:"download-info,omitempty"`
	SideInfo     *snap.SideInfo     `json:"side-info,omitempty"`
}

SnapSetup holds the necessary snap details to perform most snap manager tasks.

func TaskSnapSetup

func TaskSnapSetup(t *state.Task) (*SnapSetup, error)

TaskSnapSetup returns the SnapSetup with task params hold by or referred to by the the task.

func (*SnapSetup) DevMode

func (ss *SnapSetup) DevMode() bool

DevMode returns true if the snap is being installed in developer mode.

func (*SnapSetup) DevModeAllowed

func (ss *SnapSetup) DevModeAllowed() bool

func (*SnapSetup) JailMode

func (ss *SnapSetup) JailMode() bool

func (*SnapSetup) MountDir

func (ss *SnapSetup) MountDir() string

func (*SnapSetup) Name

func (ss *SnapSetup) Name() string

func (*SnapSetup) Revision

func (ss *SnapSetup) Revision() snap.Revision

func (*SnapSetup) TryMode

func (ss *SnapSetup) TryMode() bool

TryMode returns true if the snap is being installed in try mode directly from a directory.

type SnapSetupFlags

type SnapSetupFlags Flags

SnapSetupFlags are flags stored in SnapSetup to control snap manager tasks.

type SnapState

type SnapState struct {
	SnapType string           `json:"type"` // Use Type and SetType
	Sequence []*snap.SideInfo `json:"sequence"`
	Active   bool             `json:"active,omitempty"`
	// Current indicates the current active revision if Active is
	// true or the last active revision if Active is false
	// (usually while a snap is being operated on or disabled)
	Current snap.Revision  `json:"current"`
	Channel string         `json:"channel,omitempty"`
	Flags   SnapStateFlags `json:"flags,omitempty"`
}

SnapState holds the state for a snap installed in the system.

func (*SnapState) Block

func (snapst *SnapState) Block() []snap.Revision

Block returns revisions that should be blocked on refreshes, computed from Sequence[currentRevisionIndex+1:].

func (*SnapState) CurrentInfo

func (snapst *SnapState) CurrentInfo() (*snap.Info, error)

CurrentInfo returns the information about the current active revision or the last active revision (if the snap is inactive). It returns the ErrNoCurrent error if snapst.Current is unset.

func (*SnapState) CurrentSideInfo

func (snapst *SnapState) CurrentSideInfo() *snap.SideInfo

CurrentSideInfo returns the side info for the revision indicated by snapst.Current in the snap revision sequence if there is one.

func (*SnapState) DevMode

func (snapst *SnapState) DevMode() bool

DevMode returns true if the snap is installed in developer mode.

func (*SnapState) DevModeAllowed

func (snapst *SnapState) DevModeAllowed() bool

func (*SnapState) HasCurrent

func (snapst *SnapState) HasCurrent() bool

HasCurrent returns whether snapst.Current is set.

func (*SnapState) JailMode

func (snapst *SnapState) JailMode() bool

func (*SnapState) LocalRevision

func (snapst *SnapState) LocalRevision() snap.Revision

LocalRevision returns the "latest" local revision. Local revisions start at -1 and are counted down.

func (*SnapState) SetDevMode

func (snapst *SnapState) SetDevMode(active bool)

SetDevMode sets/clears the DevMode flag in the SnapState.

func (*SnapState) SetJailMode

func (snapst *SnapState) SetJailMode(active bool)

SetJailMode sets/clears the JailMode flag in the SnapState.

func (*SnapState) SetTryMode

func (snapst *SnapState) SetTryMode(active bool)

SetTryMode sets/clears the TryMode flag in the SnapState.

func (*SnapState) SetType

func (snapst *SnapState) SetType(typ snap.Type)

SetType records the type of the snap.

func (*SnapState) TryMode

func (snapst *SnapState) TryMode() bool

TryMode returns true if the snap is installed in `try` mode as an unpacked directory.

func (*SnapState) Type

func (snapst *SnapState) Type() (snap.Type, error)

Type returns the type of the snap or an error. Should never error if Current is not nil.

type SnapStateFlags

type SnapStateFlags Flags

SnapStateFlags are flags stored in SnapState.

type StoreService

type StoreService interface {
	Snap(name, channel string, devmode bool, user *auth.UserState) (*snap.Info, error)
	Find(query, channel string, user *auth.UserState) ([]*snap.Info, error)
	ListRefresh([]*store.RefreshCandidate, *auth.UserState) ([]*snap.Info, error)
	SuggestedCurrency() string

	Download(string, *snap.DownloadInfo, progress.Meter, *auth.UserState) (string, error)
	Buy(options *store.BuyOptions) (*store.BuyResult, error)
	PaymentMethods(*auth.UserState) (*store.PaymentInformation, error)
}

A StoreService can find, list available updates and download snaps.

func Store

func Store(s *state.State) StoreService

Store returns the store service used by the snapstate package.

type TaskProgressAdapter

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

TaskProgressAdapter adapts the progress.Meter to the task progress until we have native install/update/remove.

func (*TaskProgressAdapter) Finished

func (t *TaskProgressAdapter) Finished()

Finished set the progress to 100%

func (*TaskProgressAdapter) Notify

func (t *TaskProgressAdapter) Notify(msg string)

Notify notifies

func (*TaskProgressAdapter) Set

func (t *TaskProgressAdapter) Set(current float64)

Set sets the current progress

func (*TaskProgressAdapter) SetTotal

func (t *TaskProgressAdapter) SetTotal(total float64)

SetTotal sets tht maximum progress

func (*TaskProgressAdapter) Spin

func (t *TaskProgressAdapter) Spin(msg string)

Spin does nothing

func (*TaskProgressAdapter) Start

func (t *TaskProgressAdapter) Start(pkg string, total float64)

Start sets total

func (*TaskProgressAdapter) Write

func (t *TaskProgressAdapter) Write(p []byte) (n int, err error)

Write does nothing

Directories

Path Synopsis
Package backend implements the low-level primitives to manage the snaps and their installation on disk.
Package backend implements the low-level primitives to manage the snaps and their installation on disk.

Jump to

Keyboard shortcuts

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