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