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