dumbcaslib

package
v0.0.0-...-2b12461 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBytes

func AddBytes(c CasTable, data []byte) (string, error)

AddBytes adds an entry in a CasTable when the data is already in memory but not yet hashed.

func EnumerateCasAsList

func EnumerateCasAsList(cas CasTable) ([]string, error)

EnumerateCasAsList returns a sorted list of all the entries in a CasTable. It is meant to be used in test.

func EnumerateNodesAsList

func EnumerateNodesAsList(nodes NodesTable) ([]string, error)

EnumerateNodesAsList returns a sorted list of all the entries. It is means for testing.

func EnumerateTree

func EnumerateTree(rootDir string) <-chan TreeItem

EnumerateTree walks the directory tree.

func LoadReaderAsJSON

func LoadReaderAsJSON(r io.Reader, value interface{}) error

LoadReaderAsJSON decodes JSON data from a io.Reader.

func Sha1Bytes

func Sha1Bytes(content []byte) string

Sha1Bytes returns the hex encoded SHA-1 from the content.

Types

type Cache

type Cache interface {
	io.Closer

	// Returns the root entry. Must be non-nil.
	Root() *EntryCache
}

Cache is a cache to entries to speed up adding elements to a CasTable.

func LoadCache

func LoadCache() (Cache, error)

LoadCache loads the cache from ~/.dumbcas/cache.json and keeps it open until the call to Close(). It is guaranteed to return a non-nil Cache instance even in case of failure to load the cache from disk and that error is non-nil.

TODO(maruel): Ensure proper file locking. One way is to always create a new file when adding data and then periodically garbage-collect the files.

func MakeMemoryCache

func MakeMemoryCache() Cache

MakeMemoryCache returns an in-memory Cache implementation. Useful for testing.

type CasTable

type CasTable interface {
	Table
	// AddEntry adds a node to the table.
	AddEntry(source io.Reader, name string) error
	// SetFsckBit sets the bit that the table needs to be checked for consistency.
	SetFsckBit()
	// GetFsckBit returns if the fsck bit is set.
	GetFsckBit() bool
	// ClearFsckBit clears the fsck bit.
	ClearFsckBit()
}

CasTable describes the interface to a content-addressed-storage.

func MakeLocalCasTable

func MakeLocalCasTable(rootDir string) (CasTable, error)

MakeLocalCasTable returns a CasTable rooted at rootDir.

func MakeMemoryCasTable

func MakeMemoryCasTable() CasTable

MakeMemoryCasTable returns a CasTable implementation that keeps all the data in memory. Is it useful for testing.

type Corruptable

type Corruptable interface {
	// Corrupt corrupts an element in the table.
	Corrupt()
}

Corruptable is implemented only by in-memory implementations for unit testing fsck-like algorithms.

type Entry

type Entry struct {
	Sha1  string            `json:"h,omitempty"`
	Size  int64             `json:"s,omitempty"`
	Files map[string]*Entry `json:"f,omitempty"`
}

Entry is an element. It can only contain the 2 firsts or the last one. TODO(maruel): Investigate if map[string]Entry could be used instead for performance reasons.

func LoadEntry

func LoadEntry(cas CasTable, hash string) (*Entry, error)

LoadEntry is an utility functiont that loads an node stored in the CasTable into an Entry instance.

func (*Entry) CountMembers

func (e *Entry) CountMembers() int

CountMembers returns the number of all children elements recursively.

func (*Entry) Print

func (e *Entry) Print(w io.Writer, indent string)

Print prints the Entry in Yaml-inspired output.

func (*Entry) ServeDir

func (e *Entry) ServeDir(w http.ResponseWriter)

ServeDir returns the child entries for an Entry.

func (*Entry) SortedFiles

func (e *Entry) SortedFiles() []string

SortedFiles returns the child entry names sorted.

type EntryCache

type EntryCache struct {
	Sha1       string
	Size       int64
	Timestamp  int64 // In Unix() epoch.
	LastTested int64 // Last time this file was tested for presence.
	Files      map[string]*EntryCache
}

EntryCache describes an entry in the cache. Can be either a file or a directory. Using this structure is more compact than a flat list for deep trees.

func FindInCache

func FindInCache(c Cache, itemPath string) *EntryCache

FindInCache finds an item in the cache or create it if not present.

func (*EntryCache) CountMembers

func (e *EntryCache) CountMembers() int

CountMembers returns the number of all items in this tree recursively.

func (*EntryCache) Print

func (e *EntryCache) Print(w io.Writer, indent string)

Print prints the EntryCache in Yaml-inspired output.

func (*EntryCache) SortedFiles

func (e *EntryCache) SortedFiles() []string

SortedFiles returns the entries in this directory sorted.

type EnumerationEntry

type EnumerationEntry struct {
	Item  string
	Error error
}

EnumerationEntry is one element in the enumeration functions.

type Node

type Node struct {
	Entry   string
	Comment string `json:",omitempty"`
}

Node is a element in the index NodesTable.

type NodesTable

type NodesTable interface {
	Table
	// AddEntry adds a node to the table.
	AddEntry(node *Node, name string) (string, error)
}

NodesTable is an index to a CasTable.

func LoadLocalNodesTable

func LoadLocalNodesTable(rootDir string, cas CasTable) (NodesTable, error)

LoadLocalNodesTable returns a NodesTable rooted at rootDir using CasTable as its data source.

func MakeMemoryNodesTable

func MakeMemoryNodesTable(cas CasTable) NodesTable

MakeMemoryNodesTable returns a NodeTable implementation all in memory.

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

ReadSeekCloser implements all of io.Reader, io.Seeker and io.Closer.

type Table

type Table interface {
	// Must be able to efficiently respond to an HTTP GET request.
	http.Handler
	// Enumerate enumerates all the entries in the table.
	Enumerate() <-chan EnumerationEntry
	// Open opens an entry for reading.
	Open(name string) (ReadSeekCloser, error)
	// Remove removes a node enumerated by Enumerate().
	Remove(name string) error
}

Table represents a flat table of data.

type TreeItem

type TreeItem struct {
	FullPath string
	os.FileInfo
	Error error
}

TreeItem is an item returned by EnumerateTree.

Jump to

Keyboard shortcuts

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