github.com/rigado/snapd@v2.42.5-go-mod+incompatible/seed/seed.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 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 seed implements loading and validating of seed data. 21 package seed 22 23 import ( 24 "errors" 25 26 "github.com/snapcore/snapd/asserts" 27 "github.com/snapcore/snapd/snap" 28 "github.com/snapcore/snapd/timings" 29 ) 30 31 var ( 32 ErrNoAssertions = errors.New("no seed assertions") 33 ErrNoMeta = errors.New("no seed metadata") 34 ) 35 36 // Snap holds the details of a snap in a seed. 37 type Snap struct { 38 Path string 39 40 SideInfo *snap.SideInfo 41 42 Essential bool 43 Required bool 44 45 // options 46 Channel string 47 DevMode bool 48 Classic bool 49 } 50 51 func (s *Snap) SnapName() string { 52 return s.SideInfo.RealName 53 } 54 55 func (s *Snap) ID() string { 56 return s.SideInfo.SnapID 57 } 58 59 // Seed supports loading assertions and seed snaps' metadata. 60 type Seed interface { 61 // LoadAssertions loads all assertions from the seed with 62 // cross-checks. A read-only view on an assertions database 63 // can be passed in together with a commitTo function which 64 // will be used to commit the assertions to the underlying 65 // database. If db is nil an internal temporary database will 66 // be setup instead. ErrNoAssertions will be returned if there 67 // is no assertions directory in the seed, this is legitimate 68 // only on classic. 69 LoadAssertions(db asserts.RODatabase, commitTo func(*asserts.Batch) error) error 70 71 // Model returns the seed provided model assertion. It is an 72 // error to call Model before LoadAssertions. 73 Model() (*asserts.Model, error) 74 75 // LoadMeta loads the seed and seed's snaps metadata. It can 76 // return ErrNoMeta if there is no metadata nor snaps in the 77 // seed, this is legitimate only on classic. It is an error to 78 // call LoadMeta before LoadAssertions. 79 LoadMeta(tm timings.Measurer) error 80 81 // UsesSnapdSnap returns whether the system as defined by the 82 // seed will use the snapd snap, after LoadMeta. 83 UsesSnapdSnap() bool 84 85 // EssentialSnaps returns the essential snaps as defined by 86 // the seed, after LoadMeta. 87 EssentialSnaps() []*Snap 88 89 // ModeSnaps returns the snaps that should be available 90 // in the given mode as defined by the seed, after LoadMeta. 91 ModeSnaps(mode string) ([]*Snap, error) 92 } 93 94 // Open returns a Seed implementation for the seed at seedDir. 95 // TODO: more parameters for the Core20 case 96 func Open(seedDir string) (Seed, error) { 97 return &seed16{seedDir: seedDir}, nil 98 }