storage

package
v0.0.0-...-a8938b0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package storage implements the various backend storage types

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(s Storage, id string, w io.Writer) error

Export outputs a tgz to a writer for a specific root

func Import

func Import(s Storage, id string, r io.Reader) error

func Register

func Register(name string, s func(config.Config) (Storage, error))

Types

type BlobReader

type BlobReader interface {
	io.ReadSeekCloser
	Size() int64
}

BlobReader is used to read blobs

type BlobWriter

type BlobWriter interface {
	io.WriteCloser
	// Hash is available after the writer is closed
	Hash() (string, error)
}

BlobWriter is used when writing blobs

type DiffEntry

type DiffEntry struct {
	Action string   `json:"action"`          // add, remove, changed
	Path   []string `json:"path"`            // path to entry
	Hash1  string   `json:"hash1,omitempty"` // hash of entry from 1
	Hash2  string   `json:"hash2,omitempty"` // hash of entry from 2
}

type DiffReport

type DiffReport struct {
	R1      string      `json:"r1"` // hash of root 1
	R2      string      `json:"r2"` // hash of root 2
	Entries []DiffEntry `json:"entries"`
}

func DiffRoots

func DiffRoots(r1, r2 *Root) (DiffReport, error)

DiffRoots compares two roots and returns a list of differences TODO: improve entry to show more than the hash and to package request/response into a single entry?

type Dir

type Dir struct {
	Entries map[string]*DirEntry `json:"entries"`
	// contains filtered or unexported fields
}

type DirEntry

type DirEntry struct {
	Hash string    `json:"hash"`
	Kind EntryKind `json:"kind"`
	// contains filtered or unexported fields
}

type EntryKind

type EntryKind int
const (
	KindDir EntryKind = iota
	KindFile
)

func (EntryKind) MarshalText

func (k EntryKind) MarshalText() ([]byte, error)

func (*EntryKind) UnmarshalText

func (k *EntryKind) UnmarshalText(b []byte) error

type FSStorage

type FSStorage struct {
	// contains filtered or unexported fields
}

func (*FSStorage) BlobCreate

func (fs *FSStorage) BlobCreate() (BlobWriter, error)

BlobCreate returns a writer for a blob

func (*FSStorage) BlobOpen

func (fs *FSStorage) BlobOpen(blob string) (BlobReader, error)

BlobOpen returns a reader for a blob

func (*FSStorage) Flush

func (fs *FSStorage) Flush() error

Flush writes any data cached to the backend storage

func (*FSStorage) Index

func (fs *FSStorage) Index() Index

Index returns the current index

func (*FSStorage) PruneCache

func (fs *FSStorage) PruneCache(time.Duration) error

PruneCache deletes any data from memory or cache that hasn't been recently accessed

func (*FSStorage) PruneStorage

func (fs *FSStorage) PruneStorage() error

PruneStorage deletes any blobs that are not used by any root

func (*FSStorage) RootCreate

func (fs *FSStorage) RootCreate() (string, *Root, error)

RootCreate returns a new root using a uuid

func (*FSStorage) RootCreateFrom

func (fs *FSStorage) RootCreateFrom(hash string) (string, *Root, error)

RootCreateFrom returns a new root using a uuid initialized from an existing hash

func (*FSStorage) RootOpen

func (fs *FSStorage) RootOpen(name string) (*Root, error)

RootOpen returns an existing root

func (*FSStorage) RootSave

func (fs *FSStorage) RootSave(r *Root) (string, error)

RootSave saves a root and adds the hash to the index

type File

type File struct {
	// contains filtered or unexported fields
}

type Index

type Index struct {
	Roots map[string]*IndexRoot `json:"roots"`
}

Index lists the known roots stored by hash

type IndexRoot

type IndexRoot struct {
	Used time.Time `json:"used,omitempty"`
}

IndexRoot describes the metadata for a root

type MemStorage

type MemStorage struct {
	// contains filtered or unexported fields
}

func (*MemStorage) BlobCreate

func (m *MemStorage) BlobCreate() (BlobWriter, error)

BlobCreate returns a writer for a blob

func (*MemStorage) BlobOpen

func (m *MemStorage) BlobOpen(blob string) (BlobReader, error)

BlobOpen returns a reader for a blob

func (*MemStorage) Flush

func (m *MemStorage) Flush() error

Flush writes any data cached to the backend storage

func (*MemStorage) Index

func (m *MemStorage) Index() Index

Index returns the current index

func (*MemStorage) PruneCache

func (m *MemStorage) PruneCache(time.Duration) error

PruneCache deletes any data from memory or cache that hasn't been recently accessed

func (*MemStorage) PruneStorage

func (m *MemStorage) PruneStorage() error

PruneStorage deletes any blobs that are not used by any root

func (*MemStorage) RootCreate

func (m *MemStorage) RootCreate() (string, *Root, error)

RootCreate returns a new root using a uuid

func (*MemStorage) RootCreateFrom

func (m *MemStorage) RootCreateFrom(hash string) (string, *Root, error)

RootCreateFrom returns a new root using a uuid initialized from an existing hash

func (*MemStorage) RootOpen

func (m *MemStorage) RootOpen(name string) (*Root, error)

RootOpen returns an existing root

func (*MemStorage) RootSave

func (m *MemStorage) RootSave(r *Root) (string, error)

RootSave saves a root and adds the hash to the index

type Root

type Root struct {
	// contains filtered or unexported fields
}

func (*Root) EntryHash

func (r *Root) EntryHash(path []string) (string, error)

EntryHash returns the hash of a path entry

func (r *Root) Link(path []string, blob string) error

Link references an existing blob as a file in a directory

func (*Root) List

func (r *Root) List(path []string) (map[string]*DirEntry, error)

List returns the directory entries in a root

func (*Root) ListHashes

func (r *Root) ListHashes() ([]string, error)

ListHashes returns a slice of hashes representing all entries in a root

func (*Root) Read

func (r *Root) Read(path []string) (BlobReader, error)

Read returns a reader for a given file

func (*Root) ReadOnly

func (r *Root) ReadOnly() bool

ReadOnly returns true if the root is read-only (loaded from an immutable hash)

func (*Root) Save

func (r *Root) Save() (string, error)

Save computes and returns the hash of the root

func (*Root) Walk

func (r *Root) Walk(fns WalkFns) error

func (*Root) Write

func (r *Root) Write(path []string) (BlobWriter, error)

type Storage

type Storage interface {
	// BlobOpen returns a reader for a blob
	BlobOpen(blob string) (BlobReader, error)
	// BlobCreate returns a writer for a blob
	BlobCreate() (BlobWriter, error)
	// Flush writes any data cached to the backend storage
	Flush() error
	// Index returns the current index
	Index() Index
	// PruneCache deletes any data from memory or cache that hasn't been recently accessed
	PruneCache(time.Duration) error
	// PruneStorage deletes any blobs that are not used by any root
	PruneStorage() error
	// RootCreate returns a new root using a uuid
	RootCreate() (string, *Root, error)
	// RootCreateFrom returns a new root using a uuid initialized from an existing hash
	RootCreateFrom(hash string) (string, *Root, error)
	// RootOpen returns an existing root
	RootOpen(name string) (*Root, error)
	// RootSave saves a root and adds the hash to the index
	RootSave(r *Root) (string, error)
}

Storage is implemented by various backings (memory, disk, OCI registry)

func Get

func Get(c config.Config) (Storage, error)

func NewFilesystem

func NewFilesystem(dir string) (Storage, error)

func NewMemory

func NewMemory() (Storage, error)

type WalkFns

type WalkFns struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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