Documentation ¶
Overview ¶
Package lightweight provides a quick way of loading things that can become snaps.
A lightweight.PartBag has a name and n versions; it might not even know its origin.
Index ¶
- Variables
- func AllPartBags() map[string]*PartBag
- type Concreter
- type PartBag
- func (bag *PartBag) ActiveIndex() int
- func (bag *PartBag) FullName() string
- func (bag *PartBag) IsInstalled(idx int) bool
- func (bag *PartBag) Load(versionIdx int) (snappy.Part, error)
- func (bag *PartBag) LoadActive() (snappy.Part, error)
- func (bag *PartBag) LoadBest() snappy.Part
- func (bag *PartBag) Map(remotePart snappy.Part) map[string]string
- func (bag *PartBag) QualifiedName() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadVersionIndex is returned by Load when asked to load a // non-existent version. ErrBadVersionIndex = errors.New("Bad version index") // ErrVersionGone is returned in the case where we find a // version and it disappears before we get to load it. ErrVersionGone = errors.New("Version gone") )
var NewConcrete = newConcreteImpl
NewConcrete is meant to be overridden in tests; is called when needing a Concreter for app/fmk/oem snaps (ie not core).
Functions ¶
Types ¶
type Concreter ¶
type Concreter interface { IsInstalled(string) bool ActiveIndex() int Load(string) (snappy.Part, error) }
Concreter hides the part-specific details of PartBags
type PartBag ¶
type PartBag struct { Name string Origin string Type pkg.Type Versions []string // contains filtered or unexported fields }
A PartBag is a lightweight object that represents and knows how to load a Part on demand.
Example ¶
package main import ( "fmt" "io/ioutil" "os" "path/filepath" "github.com/ubuntu-core/snappy/dirs" "github.com/ubuntu-core/snappy/pkg/lightweight" ) func main() { d, _ := ioutil.TempDir("", "test-xyzzy-") defer os.RemoveAll(d) dirs.SetRootDir(d) os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.1"), 0755) os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.2"), 0755) os.MkdirAll(filepath.Join(dirs.SnapDataDir, "foo.bar", "0.5"), 0755) os.MkdirAll(filepath.Join(dirs.SnapDataDir, "baz", "0.4"), 0755) os.MkdirAll(filepath.Join(dirs.SnapDataDir, "qux", "0.5"), 0755) os.MkdirAll(filepath.Join(dirs.SnapOemDir, "qux", "0.5"), 0755) bags := lightweight.AllPartBags() for _, k := range []string{"foo.bar", "baz", "qux"} { bag := bags[k] fmt.Printf("Found %d versions for %s, type %q: %s\n", len(bag.Versions), bag.QualifiedName(), bag.Type, bag.Versions) } }
Output: Found 3 versions for foo.bar, type "app": [0.5 0.2 0.1] Found 1 versions for baz, type "framework": [0.4] Found 1 versions for qux, type "oem": [0.5]
func PartBagByName ¶
PartBagByName finds a PartBag with the given name.
func (*PartBag) ActiveIndex ¶
ActiveIndex returns the index of the active version, or -1
func (*PartBag) IsInstalled ¶
IsInstalled checks whether the given part is installed
func (*PartBag) LoadActive ¶
LoadActive gets the active index and loads it. If none active, returns a nil Part and ErrBadVersionIndex.
func (*PartBag) LoadBest ¶
LoadBest looks for the best candidate Part and loads it.
If there is an active part, load that. Otherwise, load the highest-versioned installed part. Otherwise, load the first removed part.
If not even a removed part can be loaded, something is wrong. Nil is returned, but you're in trouble (did the filesystem just disappear under us?).
func (*PartBag) Map ¶
Map this PartBag into a map[string]string, augmenting it with the given (purportedly remote) Part.
It is a programming error (->panic) to call Map on a nil *PartBag with a nil Part. PartBag or part may be nil, but not both.
Also may panic if the remote part is nil and LoadBest can't load a Part at all.
func (*PartBag) QualifiedName ¶
QualifiedName of the PartBag.
because PartBags read their origin from the filesystem, you don't need to check the pacakge type.