Documentation ¶
Overview ¶
Package backend implements the low-level primitives to manage the snaps and their installation on disk.
- Copyright (C) 2020 Canonical Ltd *
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 3 as
- published by the Free Software Foundation. *
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details. *
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. *
Index ¶
- func GenerateSnapdWrappers(s *snap.Info, opts *GenerateSnapdWrappersOptions) (wrappers.SnapdRestart, error)
- func MockAllUsers(f func(options *dirs.SnapDirOptions) ([]*user.User, error)) func()
- func OpenComponentFile(compPath string, snapInfo *snap.Info, csi *snap.ComponentSideInfo) (*snap.ComponentInfo, snap.Container, error)
- func OpenSnapFile(snapPath string, sideInfo *snap.SideInfo) (*snap.Info, snap.Container, error)
- func WithSnapLock(info *snap.Info, action func() error) error
- type Alias
- type Backend
- func (b Backend) Candidate(*snap.SideInfo)
- func (b Backend) ClearTrashedData(oldSnap *snap.Info)
- func (b Backend) CopySnapData(newSnap, oldSnap *snap.Info, opts *dirs.SnapDirOptions, meter progress.Meter) error
- func (b Backend) CurrentInfo(*snap.Info)
- func (b Backend) DiscardSnapNamespace(snapName string) error
- func (b Backend) HideSnapData(snapName string) error
- func (b Backend) InitExposedSnapHome(snapName string, rev snap.Revision, opts *dirs.SnapDirOptions) (undoInfo *UndoInfo, err error)
- func (b Backend) InitXDGDirs(info *snap.Info) error
- func (b Backend) KillSnapApps(snapName string, reason snap.AppKillReason, tm timings.Measurer) error
- func (b Backend) LinkComponent(cpi snap.ContainerPlaceInfo, snapRev snap.Revision) error
- func (b Backend) LinkSnap(info *snap.Info, dev snap.Device, linkCtx LinkContext, tm timings.Measurer) (e error)
- func (b Backend) MaybeSetNextBoot(info *snap.Info, dev snap.Device, isUndo bool) (boot.RebootInfo, error)
- func (b Backend) QueryDisabledServices(info *snap.Info, pb progress.Meter) (*wrappers.DisabledServices, error)
- func (b Backend) RemoveAllSnapAppArmorProfiles() error
- func (b Backend) RemoveComponentDir(cpi snap.ContainerPlaceInfo) error
- func (b Backend) RemoveComponentFiles(cpi snap.ContainerPlaceInfo, installRecord *InstallRecord, dev snap.Device, ...) error
- func (b Backend) RemoveContainerMountUnits(s snap.ContainerPlaceInfo, meter progress.Meter) error
- func (b Backend) RemoveKernelSnapSetup(instanceName string, rev snap.Revision, meter progress.Meter) error
- func (b Backend) RemoveSnapAliases(snapName string) error
- func (b Backend) RemoveSnapCommonData(snap *snap.Info, opts *dirs.SnapDirOptions) error
- func (b Backend) RemoveSnapData(snap *snap.Info, opts *dirs.SnapDirOptions) error
- func (b Backend) RemoveSnapDataDir(info *snap.Info, hasOtherInstances bool, opts *dirs.SnapDirOptions) error
- func (b Backend) RemoveSnapDir(s snap.PlaceInfo, hasOtherInstances bool) error
- func (b Backend) RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, installRecord *InstallRecord, dev snap.Device, ...) error
- func (b Backend) RemoveSnapInhibitLock(instanceName string, stateUnlocker runinhibit.Unlocker) error
- func (b Backend) RemoveSnapSaveData(snapInfo *snap.Info, dev snap.Device) error
- func (b Backend) RunInhibitSnapForUnlink(info *snap.Info, hint runinhibit.Hint, stateUnlocker runinhibit.Unlocker, ...) (lock *osutil.FileLock, err error)
- func (b Backend) SetupComponent(compFilePath string, compPi snap.ContainerPlaceInfo, dev snap.Device, ...) (installRecord *InstallRecord, err error)
- func (b Backend) SetupKernelModulesComponents(currentComps, finalComps []*snap.ComponentSideInfo, ksnapName string, ...) (err error)
- func (b Backend) SetupKernelSnap(instanceName string, rev snap.Revision, meter progress.Meter) (err error)
- func (b Backend) SetupSnap(snapFilePath, instanceName string, sideInfo *snap.SideInfo, dev snap.Device, ...) (snapType snap.Type, installRecord *InstallRecord, err error)
- func (b Backend) SetupSnapSaveData(info *snap.Info, dev snap.Device, meter progress.Meter) error
- func (b Backend) StartServices(apps []*snap.AppInfo, disabledSvcs *wrappers.DisabledServices, ...) error
- func (b Backend) StopServices(apps []*snap.AppInfo, reason snap.ServiceStopReason, meter progress.Meter, ...) error
- func (b Backend) UndoCopySnapData(newInfo, oldInfo *snap.Info, opts *dirs.SnapDirOptions, _ progress.Meter) error
- func (b Backend) UndoHideSnapData(snapName string) error
- func (b Backend) UndoInitExposedSnapHome(snapName string, undoInfo *UndoInfo) error
- func (b Backend) UndoSetupComponent(cpi snap.ContainerPlaceInfo, installRecord *InstallRecord, dev snap.Device, ...) error
- func (b Backend) UndoSetupSnap(s snap.PlaceInfo, typ snap.Type, installRecord *InstallRecord, dev snap.Device, ...) error
- func (b Backend) UndoSetupSnapSaveData(newInfo, oldInfo *snap.Info, dev snap.Device, meter progress.Meter) error
- func (b Backend) UnlinkComponent(cpi snap.ContainerPlaceInfo, snapRev snap.Revision) error
- func (b Backend) UnlinkSnap(info *snap.Info, linkCtx LinkContext, meter progress.Meter) error
- func (b Backend) UpdateAliases(add []*Alias, remove []*Alias) error
- type GenerateSnapdWrappersOptions
- type InstallRecord
- type LinkContext
- type SetupSnapOptions
- type UndoInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateSnapdWrappers ¶
func GenerateSnapdWrappers(s *snap.Info, opts *GenerateSnapdWrappersOptions) (wrappers.SnapdRestart, error)
func MockAllUsers ¶
func MockAllUsers(f func(options *dirs.SnapDirOptions) ([]*user.User, error)) func()
MockAllUsers allows tests to mock snap.AllUsers. Panics if called outside of tests.
func OpenComponentFile ¶
func OpenComponentFile(compPath string, snapInfo *snap.Info, csi *snap.ComponentSideInfo) (*snap.ComponentInfo, snap.Container, error)
OpenComponentFile opens a component blob returning a snap.ComponentInfo and a corresponding snap.Container. Assumes the file was verified beforehand or the user asked for --dangerous. The returned snap.ComponentInfo is completed by the provided snap.Info and snap.ComponentSideInfo, if they are not nil.
func OpenSnapFile ¶
OpenSnapFile opens a snap blob returning both a snap.Info completed with sideInfo (if not nil) and a corresponding snap.Container. Assumes the file was verified beforehand or the user asked for --dangerous.
func WithSnapLock ¶
WithSnapLock executes given action with the snap lock held.
The lock is also used by snap-confine during pre-snap mount namespace initialization. Holding it allows to ensure mutual exclusion during the process of preparing a new snap app or hook processes. It does not prevent existing application or hook processes from forking.
Note that this is not a method of the Backend type, so that it can be invoked from doInstall, which does not have access to a backend object.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend exposes all the low-level primitives to manage snaps and their installation on disk.
func NewForPreseedMode ¶
func NewForPreseedMode() Backend
func (Backend) ClearTrashedData ¶
ClearTrashedData removes the trash. It returns no errors on the assumption that it is called very late in the game.
func (Backend) CopySnapData ¶
func (b Backend) CopySnapData(newSnap, oldSnap *snap.Info, opts *dirs.SnapDirOptions, meter progress.Meter) error
CopySnapData makes a copy of oldSnap data for newSnap in its data directories.
func (Backend) DiscardSnapNamespace ¶
Discard the mount namespace of a given snap.
func (Backend) HideSnapData ¶
HideSnapData moves the snap's data directory in ~/snap into the corresponding ~/.snap/data directory, for each user using the snap.
func (Backend) InitExposedSnapHome ¶
func (b Backend) InitExposedSnapHome(snapName string, rev snap.Revision, opts *dirs.SnapDirOptions) (undoInfo *UndoInfo, err error)
InitExposedSnapHome creates and initializes ~/Snap/<snapName> based on the specified revision. If no error occurred, returns a non-nil undoInfo so that the operation can be undone. If an error occurred, an attempt is made to undo so no undoInfo is returned.
func (Backend) InitXDGDirs ¶
InitXDGDirs renames .local/share, .config and .cache directories to their post core22 migration locations. Directories that don't exist are created. Must be invoked after the revisioned data has been migrated.
func (Backend) KillSnapApps ¶
func (Backend) LinkComponent ¶
func (Backend) LinkSnap ¶
func (b Backend) LinkSnap(info *snap.Info, dev snap.Device, linkCtx LinkContext, tm timings.Measurer) (e error)
LinkSnap makes the snap available by generating wrappers and setting the current symlinks.
func (Backend) MaybeSetNextBoot ¶
func (b Backend) MaybeSetNextBoot(info *snap.Info, dev snap.Device, isUndo bool) (boot.RebootInfo, error)
MaybeSetNextBoot configures the system for a reboot if necesssary because of a snap refresh. isUndo must be set when we are installing the previous snap while performing a revert of the latest one that was installed
func (Backend) QueryDisabledServices ¶
func (Backend) RemoveAllSnapAppArmorProfiles ¶
Discard all snap apparmor profiles.
func (Backend) RemoveComponentDir ¶
func (b Backend) RemoveComponentDir(cpi snap.ContainerPlaceInfo) error
func (Backend) RemoveComponentFiles ¶
func (b Backend) RemoveComponentFiles(cpi snap.ContainerPlaceInfo, installRecord *InstallRecord, dev snap.Device, meter progress.Meter) error
RemoveComponentFiles unmounts and removes component files from the disk.
func (Backend) RemoveContainerMountUnits ¶
func (Backend) RemoveKernelSnapSetup ¶
func (Backend) RemoveSnapAliases ¶
RemoveSnapAliases removes all the aliases targeting the given snap.
func (Backend) RemoveSnapCommonData ¶
RemoveSnapCommonData removes the data common between versions of the given snap.
func (Backend) RemoveSnapData ¶
RemoveSnapData removes the data for the given version of the given snap.
func (Backend) RemoveSnapDataDir ¶
func (b Backend) RemoveSnapDataDir(info *snap.Info, hasOtherInstances bool, opts *dirs.SnapDirOptions) error
RemoveSnapDataDir removes base snap data directories
func (Backend) RemoveSnapDir ¶
func (Backend) RemoveSnapFiles ¶
func (b Backend) RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, installRecord *InstallRecord, dev snap.Device, meter progress.Meter) error
RemoveSnapFiles removes the snap files from the disk after unmounting the snap.
func (Backend) RemoveSnapInhibitLock ¶
func (b Backend) RemoveSnapInhibitLock(instanceName string, stateUnlocker runinhibit.Unlocker) error
RemoveSnapInhibitLock removes the file controlling inhibition of "snap run".
func (Backend) RemoveSnapSaveData ¶
RemoveSnapSaveData removes the common save data in the case of a complete removal of a snap.
func (Backend) RunInhibitSnapForUnlink ¶
func (Backend) SetupComponent ¶
func (b Backend) SetupComponent(compFilePath string, compPi snap.ContainerPlaceInfo, dev snap.Device, meter progress.Meter) (installRecord *InstallRecord, err error)
SetupComponent prepares and mounts a component for further processing.
func (Backend) SetupKernelModulesComponents ¶
func (b Backend) SetupKernelModulesComponents(currentComps, finalComps []*snap.ComponentSideInfo, ksnapName string, ksnapRev snap.Revision, meter progress.Meter) (err error)
SetupKernelModulesComponents changes kernel-modules configuration by installing currentComps. The components currently active are currentComps, while ksnapName and ksnapRev identify the currently active kernel.
func (Backend) SetupKernelSnap ¶
func (b Backend) SetupKernelSnap(instanceName string, rev snap.Revision, meter progress.Meter) (err error)
SetupKernelSnap does extra configuration for kernel snaps.
func (Backend) SetupSnap ¶
func (b Backend) SetupSnap(snapFilePath, instanceName string, sideInfo *snap.SideInfo, dev snap.Device, setupOpts *SetupSnapOptions, meter progress.Meter) (snapType snap.Type, installRecord *InstallRecord, err error)
SetupSnap does prepare and mount the snap for further processing.
func (Backend) SetupSnapSaveData ¶
func (Backend) StartServices ¶
func (Backend) StopServices ¶
func (Backend) UndoCopySnapData ¶
func (b Backend) UndoCopySnapData(newInfo, oldInfo *snap.Info, opts *dirs.SnapDirOptions, _ progress.Meter) error
UndoCopySnapData removes the copy that may have been done for newInfo snap of oldInfo snap data and also the data directories that may have been created for newInfo snap.
func (Backend) UndoHideSnapData ¶
UndoHideSnapData moves the snap's data directory in ~/.snap/data into ~/snap, for each user using the snap.
func (Backend) UndoInitExposedSnapHome ¶
UndoInitExposedSnapHome undoes the ~/Snap initialization according to the undoInfo.
func (Backend) UndoSetupComponent ¶
func (b Backend) UndoSetupComponent(cpi snap.ContainerPlaceInfo, installRecord *InstallRecord, dev snap.Device, meter progress.Meter) error
UndoSetupComponent undoes the work of SetupComponent using RemoveComponentFiles.
func (Backend) UndoSetupSnap ¶
func (b Backend) UndoSetupSnap(s snap.PlaceInfo, typ snap.Type, installRecord *InstallRecord, dev snap.Device, meter progress.Meter) error
UndoSetupSnap undoes the work of SetupSnap using RemoveSnapFiles.
func (Backend) UndoSetupSnapSaveData ¶
func (Backend) UnlinkComponent ¶
func (Backend) UnlinkSnap ¶
UnlinkSnap makes the snap unavailable to the system removing wrappers and symlinks. The firstInstallUndo is true when undoing the first installation of the snap.
type GenerateSnapdWrappersOptions ¶
type GenerateSnapdWrappersOptions struct {
Preseeding bool
}
GenerateSnapdWrappersOptions carries options for GenerateSnapdWrappers.
type InstallRecord ¶
type InstallRecord struct { // TargetSnapExisted indicates that the target .snap file under /var/lib/snapd/snap already existed when the // backend attempted SetupSnap() through squashfs Install() and should be kept. TargetSnapExisted bool `json:"target-snap-existed,omitempty"` }
InstallRecord keeps a record of what installation effectively did as hints about what needs to be undone in case of failure.
type LinkContext ¶
type LinkContext struct { // FirstInstall indicates whether this is the first time given snap is // installed FirstInstall bool // ServiceOptions is used to configure services. ServiceOptions *wrappers.SnapServiceOptions // RunInhibitHint is used only in Unlink snap, and can be used to // establish run inhibition lock for refresh operations. RunInhibitHint runinhibit.Hint // StateUnlocker is passed to inhibition lock operations. StateUnlocker runinhibit.Unlocker // RequireMountedSnapdSnap indicates that the apps and services // generated when linking need to use tooling from the snapd snap mount. RequireMountedSnapdSnap bool // SkipBinaries indicates that we should skip removing snap binaries, // icons and desktop files in UnlinkSnap SkipBinaries bool // HasOtherInstances indicates that other instances of the snap are // already installed in the system. HasOtherInstances bool }
LinkContext carries additional information about the current or the previous state of the snap
type SetupSnapOptions ¶
type SetupSnapOptions struct {
SkipKernelExtraction bool
}