github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/overlord/snapstate/backend.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2018 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package snapstate
    21  
    22  import (
    23  	"context"
    24  	"io"
    25  
    26  	"github.com/snapcore/snapd/asserts"
    27  	"github.com/snapcore/snapd/boot"
    28  	"github.com/snapcore/snapd/client"
    29  	"github.com/snapcore/snapd/cmd/snaplock/runinhibit"
    30  	"github.com/snapcore/snapd/osutil"
    31  	"github.com/snapcore/snapd/overlord/auth"
    32  	"github.com/snapcore/snapd/overlord/snapstate/backend"
    33  	"github.com/snapcore/snapd/progress"
    34  	"github.com/snapcore/snapd/snap"
    35  	"github.com/snapcore/snapd/snap/channel"
    36  	"github.com/snapcore/snapd/snap/naming"
    37  	"github.com/snapcore/snapd/store"
    38  	"github.com/snapcore/snapd/timings"
    39  )
    40  
    41  // A StoreService can find, list available updates and download snaps.
    42  type StoreService interface {
    43  	EnsureDeviceSession() (*auth.DeviceState, error)
    44  
    45  	SnapInfo(ctx context.Context, spec store.SnapSpec, user *auth.UserState) (*snap.Info, error)
    46  	SnapExists(ctx context.Context, spec store.SnapSpec, user *auth.UserState) (naming.SnapRef, *channel.Channel, error)
    47  	Find(ctx context.Context, search *store.Search, user *auth.UserState) ([]*snap.Info, error)
    48  
    49  	SnapAction(ctx context.Context, currentSnaps []*store.CurrentSnap, actions []*store.SnapAction, assertQuery store.AssertionQuery, user *auth.UserState, opts *store.RefreshOptions) ([]store.SnapActionResult, []store.AssertionResult, error)
    50  
    51  	Sections(ctx context.Context, user *auth.UserState) ([]string, error)
    52  	WriteCatalogs(ctx context.Context, names io.Writer, adder store.SnapAdder) error
    53  
    54  	Download(context.Context, string, string, *snap.DownloadInfo, progress.Meter, *auth.UserState, *store.DownloadOptions) error
    55  	DownloadStream(context.Context, string, *snap.DownloadInfo, int64, *auth.UserState) (r io.ReadCloser, status int, err error)
    56  
    57  	Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error)
    58  	SeqFormingAssertion(assertType *asserts.AssertionType, sequenceKey []string, sequence int, user *auth.UserState) (asserts.Assertion, error)
    59  	DownloadAssertions([]string, *asserts.Batch, *auth.UserState) error
    60  
    61  	SuggestedCurrency() string
    62  	Buy(options *client.BuyOptions, user *auth.UserState) (*client.BuyResult, error)
    63  	ReadyToBuy(*auth.UserState) error
    64  	ConnectivityCheck() (map[string]bool, error)
    65  	CreateCohorts(context.Context, []string) (map[string]string, error)
    66  
    67  	LoginUser(username, password, otp string) (string, string, error)
    68  	UserInfo(email string) (userinfo *store.User, err error)
    69  }
    70  
    71  type managerBackend interface {
    72  	// install related
    73  	SetupSnap(snapFilePath, instanceName string, si *snap.SideInfo, dev boot.Device, meter progress.Meter) (snap.Type, *backend.InstallRecord, error)
    74  	CopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error
    75  	LinkSnap(info *snap.Info, dev boot.Device, linkCtx backend.LinkContext, tm timings.Measurer) (rebootRequired bool, err error)
    76  	StartServices(svcs []*snap.AppInfo, disabledSvcs []string, meter progress.Meter, tm timings.Measurer) error
    77  	StopServices(svcs []*snap.AppInfo, reason snap.ServiceStopReason, meter progress.Meter, tm timings.Measurer) error
    78  	ServicesEnableState(info *snap.Info, meter progress.Meter) (map[string]bool, error)
    79  	QueryDisabledServices(info *snap.Info, pb progress.Meter) ([]string, error)
    80  
    81  	// the undoers for install
    82  	UndoSetupSnap(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error
    83  	UndoCopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error
    84  	// cleanup
    85  	ClearTrashedData(oldSnap *snap.Info)
    86  
    87  	// remove related
    88  	UnlinkSnap(info *snap.Info, linkCtx backend.LinkContext, meter progress.Meter) error
    89  	RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error
    90  	RemoveSnapDir(s snap.PlaceInfo, hasOtherInstances bool) error
    91  	RemoveSnapData(info *snap.Info) error
    92  	RemoveSnapCommonData(info *snap.Info) error
    93  	RemoveSnapDataDir(info *snap.Info, hasOtherInstances bool) error
    94  	DiscardSnapNamespace(snapName string) error
    95  	RemoveSnapInhibitLock(snapName string) error
    96  
    97  	// alias related
    98  	UpdateAliases(add []*backend.Alias, remove []*backend.Alias) error
    99  	RemoveSnapAliases(snapName string) error
   100  
   101  	// testing helpers
   102  	CurrentInfo(cur *snap.Info)
   103  	Candidate(sideInfo *snap.SideInfo)
   104  
   105  	// refresh related
   106  	RunInhibitSnapForUnlink(info *snap.Info, hint runinhibit.Hint, decision func() error) (*osutil.FileLock, error)
   107  	// (not a backend method because doInstall cannot access the backend)
   108  	// WithSnapLock(info *snap.Info, action func() error) error
   109  }