storage

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseImagesPath = "images"

BaseImagesPath is the container where images metadata is found.

View Source
var BaseToolsPath = "tools"

BaseToolsPath is the container where tools tarballs and metadata are found.

Functions

func Get

func Get(stor StorageReader, name string) (io.ReadCloser, error)

Get gets the named file from stor using the stor's default consistency strategy.

func GetWithRetry

func GetWithRetry(stor StorageReader, name string, attempt utils.AttemptStrategy) (r io.ReadCloser, err error)

GetWithRetry gets the named file from stor using the specified attempt strategy.

TODO(katco): 2016-08-09: lp:1611427

func List

func List(stor StorageReader, prefix string) ([]string, error)

List lists the files matching prefix from stor using the stor's default consistency strategy.

func ListWithRetry

func ListWithRetry(stor StorageReader, prefix string, attempt utils.AttemptStrategy) (list []string, err error)

ListWithRetry lists the files matching prefix from stor using the specified attempt strategy.

TODO(katco): 2016-08-09: lp:1611427

func NewStorageSimpleStreamsDataSource

func NewStorageSimpleStreamsDataSource(description string, storage StorageReader, basePath string, priority int, requireSigned bool) simplestreams.DataSource

NewStorageSimpleStreamsDataSource returns a new datasource reading from the specified storage.

func RemoveAll

func RemoveAll(stor Storage) error

RemoveAll is a default implementation for StorageWriter.RemoveAll. Providers may have more efficient implementations, or better error handling, or safeguards against races with other users of the same storage medium. But a simple way to implement RemoveAll would be to delegate to here.

func TestingGetAllowRetry

func TestingGetAllowRetry(s simplestreams.DataSource) (bool, ok bool)

TestingGetAllowRetry is used in tests which need to see if allowRetry has been set on a storageSimpleStreamsDataSource.

Types

type Storage

type Storage interface {
	StorageReader
	StorageWriter
}

Storage represents storage that can be both read and written.

type StorageReader

type StorageReader interface {
	// Get opens the given storage file and returns a ReadCloser
	// that can be used to read its contents.  It is the caller's
	// responsibility to close it after use.  If the name does not
	// exist, it should return a *NotFoundError.
	Get(name string) (io.ReadCloser, error)

	// List lists all names in the storage with the given prefix, in
	// alphabetical order.  The names in the storage are considered
	// to be in a flat namespace, so the prefix may include slashes
	// and the names returned are the full names for the matching
	// entries.
	List(prefix string) ([]string, error)

	// URL returns a URL that can be used to access the given storage file.
	URL(name string) (string, error)

	// DefaultConsistencyStrategy returns the appropriate polling for waiting
	// for this storage to become consistent.
	// If the storage implementation has immediate consistency, the
	// strategy won't need to wait at all.  But for eventually-consistent
	// storage backends a few seconds of polling may be needed.
	//
	// TODO(katco): 2016-08-09: lp:1611427
	DefaultConsistencyStrategy() utils.AttemptStrategy

	// ShouldRetry returns true is the specified error is such that an
	// operation can be performed again with a chance of success. This is
	// typically the case where the storage implementation does not have
	// immediate consistency and needs to be given a chance to "catch up".
	ShouldRetry(error) bool
}

A StorageReader can retrieve and list files from a storage provider.

type StorageWriter

type StorageWriter interface {
	// Put reads from r and writes to the given storage file.
	// The length must give the total length of the file.
	Put(name string, r io.Reader, length int64) error

	// Remove removes the given file from the environment's
	// storage. It should not return an error if the file does
	// not exist.
	Remove(name string) error

	// RemoveAll deletes all files that have been stored here.
	// If the underlying storage implementation may be shared
	// with other actors, it must be sure not to delete their
	// file as well.
	// Nevertheless, use with care!  This method is only mean
	// for cleaning up an environment that's being destroyed.
	RemoveAll() error
}

A StorageWriter adds and removes files in a storage provider.

Jump to

Keyboard shortcuts

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