github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/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 SeqFormingAssertion(assertType *asserts.AssertionType, sequenceKey []string, sequence int, user *auth.UserState) (asserts.Assertion, error) 56 DownloadAssertions([]string, *asserts.Batch, *auth.UserState) error 57 58 SuggestedCurrency() string 59 Buy(options *client.BuyOptions, user *auth.UserState) (*client.BuyResult, error) 60 ReadyToBuy(*auth.UserState) error 61 ConnectivityCheck() (map[string]bool, error) 62 CreateCohorts(context.Context, []string) (map[string]string, error) 63 64 LoginUser(username, password, otp string) (string, string, error) 65 UserInfo(email string) (userinfo *store.User, err error) 66 } 67 68 type managerBackend interface { 69 // install related 70 SetupSnap(snapFilePath, instanceName string, si *snap.SideInfo, dev boot.Device, meter progress.Meter) (snap.Type, *backend.InstallRecord, error) 71 CopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error 72 LinkSnap(info *snap.Info, dev boot.Device, linkCtx backend.LinkContext, tm timings.Measurer) (rebootRequired bool, err error) 73 StartServices(svcs []*snap.AppInfo, disabledSvcs []string, meter progress.Meter, tm timings.Measurer) error 74 StopServices(svcs []*snap.AppInfo, reason snap.ServiceStopReason, meter progress.Meter, tm timings.Measurer) error 75 ServicesEnableState(info *snap.Info, meter progress.Meter) (map[string]bool, error) 76 QueryDisabledServices(info *snap.Info, pb progress.Meter) ([]string, error) 77 78 // the undoers for install 79 UndoSetupSnap(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error 80 UndoCopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter) error 81 // cleanup 82 ClearTrashedData(oldSnap *snap.Info) 83 84 // remove related 85 UnlinkSnap(info *snap.Info, linkCtx backend.LinkContext, meter progress.Meter) error 86 RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, installRecord *backend.InstallRecord, dev boot.Device, meter progress.Meter) error 87 RemoveSnapDir(s snap.PlaceInfo, hasOtherInstances bool) error 88 RemoveSnapData(info *snap.Info) error 89 RemoveSnapCommonData(info *snap.Info) error 90 RemoveSnapDataDir(info *snap.Info, hasOtherInstances bool) error 91 DiscardSnapNamespace(snapName string) error 92 RemoveSnapInhibitLock(snapName string) error 93 94 // alias related 95 UpdateAliases(add []*backend.Alias, remove []*backend.Alias) error 96 RemoveSnapAliases(snapName string) error 97 98 // testing helpers 99 CurrentInfo(cur *snap.Info) 100 Candidate(sideInfo *snap.SideInfo) 101 102 // refresh related 103 RunInhibitSnapForUnlink(info *snap.Info, hint runinhibit.Hint, decision func() error) (*osutil.FileLock, error) 104 // (not a backend method because doInstall cannot access the backend) 105 // WithSnapLock(info *snap.Info, action func() error) error 106 }