Documentation
¶
Index ¶
- func AddBytes(c CasTable, data []byte) (string, error)
- func EnumerateCasAsList(cas CasTable) ([]string, error)
- func EnumerateNodesAsList(nodes NodesTable) ([]string, error)
- func EnumerateTree(rootDir string) <-chan TreeItem
- func LoadReaderAsJSON(r io.Reader, value interface{}) error
- func Sha1Bytes(content []byte) string
- type Cache
- type CasTable
- type Corruptable
- type Entry
- type EntryCache
- type EnumerationEntry
- type Node
- type NodesTable
- type ReadSeekCloser
- type Table
- type TreeItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddBytes ¶
AddBytes adds an entry in a CasTable when the data is already in memory but not yet hashed.
func EnumerateCasAsList ¶
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 ¶
EnumerateTree walks the directory tree.
func LoadReaderAsJSON ¶
LoadReaderAsJSON decodes JSON data from a io.Reader.
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 ¶
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 ¶
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 ¶
LoadEntry is an utility functiont that loads an node stored in the CasTable into an Entry instance.
func (*Entry) CountMembers ¶
CountMembers returns the number of all children elements recursively.
func (*Entry) ServeDir ¶
func (e *Entry) ServeDir(w http.ResponseWriter)
ServeDir returns the child entries for an Entry.
func (*Entry) SortedFiles ¶
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 ¶
EnumerationEntry is one element in the enumeration functions.
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 ¶
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.