lightweight

package
v0.0.0-...-0579a83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2015 License: GPL-3.0 Imports: 12 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

func AllPartBags

func AllPartBags() map[string]*PartBag

AllPartBags the PartBags in the system.

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

func PartBagByName(name string, origin string) *PartBag

PartBagByName finds a PartBag with the given name.

func (*PartBag) ActiveIndex

func (bag *PartBag) ActiveIndex() int

ActiveIndex returns the index of the active version, or -1

func (*PartBag) FullName

func (bag *PartBag) FullName() string

FullName of the PartBag

func (*PartBag) IsInstalled

func (bag *PartBag) IsInstalled(idx int) bool

IsInstalled checks whether the given part is installed

func (*PartBag) Load

func (bag *PartBag) Load(versionIdx int) (snappy.Part, error)

Load a Part from the PartBag

func (*PartBag) LoadActive

func (bag *PartBag) LoadActive() (snappy.Part, error)

LoadActive gets the active index and loads it. If none active, returns a nil Part and ErrBadVersionIndex.

func (*PartBag) LoadBest

func (bag *PartBag) LoadBest() snappy.Part

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

func (bag *PartBag) Map(remotePart snappy.Part) map[string]string

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

func (bag *PartBag) QualifiedName() string

QualifiedName of the PartBag.

because PartBags read their origin from the filesystem, you don't need to check the pacakge type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL