github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/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/overlord/auth" 30 "github.com/snapcore/snapd/overlord/snapstate/backend" 31 "github.com/snapcore/snapd/progress" 32 "github.com/snapcore/snapd/snap" 33 "github.com/snapcore/snapd/store" 34 "github.com/snapcore/snapd/timings" 35 ) 36 37 // A StoreService can find, list available updates and download snaps. 38 type StoreService interface { 39 EnsureDeviceSession() (*auth.DeviceState, error) 40 41 SnapInfo(ctx context.Context, spec store.SnapSpec, user *auth.UserState) (*snap.Info, error) 42 Find(ctx context.Context, search *store.Search, user *auth.UserState) ([]*snap.Info, error) 43 44 SnapAction(ctx context.Context, currentSnaps []*store.CurrentSnap, actions []*store.SnapAction, assertQuery store.AssertionQuery, user *auth.UserState, opts *store.RefreshOptions) ([]store.SnapActionResult, []store.AssertionResult, error) 45 46 Sections(ctx context.Context, user *auth.UserState) ([]string, error) 47 WriteCatalogs(ctx context.Context, names io.Writer, adder store.SnapAdder) error 48 49 Download(context.Context, string, string, *snap.DownloadInfo, progress.Meter, *auth.UserState, *store.DownloadOptions) error 50 DownloadStream(context.Context, string, *snap.DownloadInfo, int64, *auth.UserState) (r io.ReadCloser, status int, err error) 51 52 Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error) 53 DownloadAssertions([]string, *asserts.Batch, *auth.UserState) error 54 55 SuggestedCurrency() string 56 Buy(options *client.BuyOptions, user *auth.UserState) (*client.BuyResult, error) 57 ReadyToBuy(*auth.UserState) error 58 ConnectivityCheck() (map[string]bool, error) 59 CreateCohorts(context.Context, []string) (map[string]string, error) 60 61 LoginUser(username, password, otp string) (string, string, error) 62 UserInfo(email string) (userinfo *store.User, err error) 63 } 64 65 type managerBackend interface { 66 // install related 67 SetupSnap(snapFilePath, instanceName string, si *snap.SideInfo, dev boot.Device, meter progress.Meter) (snap.Type, *backend.InstallRecord, error) 68 CopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error 69 LinkSnap(info *snap.Info, dev boot.Device, linkCtx backend.LinkContext, tm timings.Measurer) (rebootRequired bool, err error) 70 StartServices(svcs []*snap.AppInfo, meter progress.Meter, tm timings.Measurer) error 71 StopServices(svcs []*snap.AppInfo, reason snap.ServiceStopReason, meter progress.Meter, tm timings.Measurer) error 72 ServicesEnableState(info *snap.Info, meter progress.Meter) (map[string]bool, error) 73 QueryDisabledServices(info *snap.Info, pb progress.Meter) ([]string, error) 74 75 // the undoers for install 76 UndoSetupSnap(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error 77 UndoCopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error 78 // cleanup 79 ClearTrashedData(oldSnap *snap.Info) 80 81 // remove related 82 UnlinkSnap(info *snap.Info, linkCtx backend.LinkContext, meter progress.Meter) error 83 RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error 84 RemoveSnapDir(s snap.PlaceInfo, hasOtherInstances bool) error 85 RemoveSnapData(info *snap.Info) error 86 RemoveSnapCommonData(info *snap.Info) error 87 RemoveSnapDataDir(info *snap.Info, hasOtherInstances bool) error 88 DiscardSnapNamespace(snapName string) error 89 90 // alias related 91 UpdateAliases(add []*backend.Alias, remove []*backend.Alias) error 92 RemoveSnapAliases(snapName string) error 93 94 // testing helpers 95 CurrentInfo(cur *snap.Info) 96 Candidate(sideInfo *snap.SideInfo) 97 }