core

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2018 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MoveDirUnknown = iota
	MoveDirSrcToDst
	MoveDirDstToSrc
	MoveDirNone
)

Variables

View Source
var (
	ErrIsGhost = errors.New("Is a ghost")
)

Functions

func AssertDir

func AssertDir(t *testing.T, lkr *Linker, path string, shouldExist bool)

func Copy

func Copy(lkr *Linker, nd n.ModNode, dstPath string) (newNode n.ModNode, err error)

func Log

func Log(lkr *Linker, fn func(cmt *n.Commit) error) error

func Mkdir

func Mkdir(lkr *Linker, repoPath string, createParents bool) (dir *n.Directory, err error)

Mkdir creates the directory at repoPath and any intermediate directories if createParents is true. It will fail if there is already a file at `repoPath` and it is not a directory.

func Move

func Move(lkr *Linker, nd n.ModNode, dstPath string) (err error)

func MustCommit

func MustCommit(t *testing.T, lkr *Linker, msg string) *n.Commit

func MustCommitIfPossible

func MustCommitIfPossible(t *testing.T, lkr *Linker, msg string) *n.Commit

func MustLookupDirectory

func MustLookupDirectory(t *testing.T, lkr *Linker, path string) *n.Directory

func MustMkdir

func MustMkdir(t *testing.T, lkr *Linker, repoPath string) *n.Directory

func MustModify

func MustModify(t *testing.T, lkr *Linker, file *n.File, seed int)

func MustMove

func MustMove(t *testing.T, lkr *Linker, nd n.ModNode, destPath string) n.ModNode

func MustRemove

func MustRemove(t *testing.T, lkr *Linker, nd n.ModNode) n.ModNode

func MustTouch

func MustTouch(t *testing.T, lkr *Linker, touchPath string, seed byte) *n.File

func MustTouchAndCommit

func MustTouchAndCommit(t *testing.T, lkr *Linker, path string, seed byte) (*n.File, *n.Commit)

func Remove

func Remove(lkr *Linker, nd n.ModNode, createGhost, force bool) (parentDir *n.Directory, ghost *n.Ghost, err error)

Remove removes a single node from a directory. `nd` is the node that shall be removed and may not be root. The parent directory is returned.

func Stage

func Stage(lkr *Linker, repoPath string, content h.Hash, size uint64, key []byte) (file *n.File, err error)

func WithDummyKv

func WithDummyKv(t *testing.T, fn func(kv db.Database))

func WithDummyLinker

func WithDummyLinker(t *testing.T, fn func(lkr *Linker))

func WithLinkerPair

func WithLinkerPair(t *testing.T, fn func(lkrSrc, lkrDst *Linker))

func WithReloadingLinker

func WithReloadingLinker(t *testing.T, fn1 func(lkr *Linker), fn2 func(lkr *Linker))

Types

type GarbageCollector

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

func NewGarbageCollector

func NewGarbageCollector(lkr *Linker, kv db.Database, kc func(nd n.Node) bool) *GarbageCollector

func (*GarbageCollector) Run

func (gc *GarbageCollector) Run(allObjects bool) error

type Linker

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

Linker implements the basic logic of brig's data model It uses an underlying key/value database to storea a Merkle-DAG with versioned metadata, similar to what git does internally.

func NewLinker

func NewLinker(kv db.Database) *Linker

NewFilesystem returns a new lkr, ready to use. It assumes the key value store is working and does no check on this.

func (*Linker) AddMoveMapping

func (lkr *Linker) AddMoveMapping(from, to n.Node) (err error)

AddMoveMapping takes note that the the node `from` has been moved to `to` in the staging commit.

func (*Linker) Atomic

func (lkr *Linker) Atomic(fn func() error) (err error)

func (*Linker) CheckoutCommit

func (lkr *Linker) CheckoutCommit(cmt *n.Commit, force bool) (err error)

CheckoutCommit resets the current staging commit back to the commit referenced by cmt. If force is false, it will check if there any staged errors in the staging area and return ErrStageNotEmpty if there are any. If force is true, all changes will be overwritten.

func (*Linker) CommitByHash

func (lkr *Linker) CommitByHash(hash h.Hash) (*n.Commit, error)

CommitByHash lookups a commit by it's hash. If the commit could not be found, nil is returned.

func (*Linker) DirectoryByHash

func (lkr *Linker) DirectoryByHash(hash h.Hash) (*n.Directory, error)

DirectoryByHash calls NodeByHash and attempts to convert it to a Directory as convinience.

func (*Linker) ExpandAbbrev

func (lkr *Linker) ExpandAbbrev(abbrev string) (h.Hash, error)

ExpandAbbrev tries to find an object reference that stats with `abbrev`. If so, it will return the respective hash for it. If none is found, it is considered as an error. If more than one was found ie.ErrAmbigious is returned.

func (*Linker) FileByHash

func (lkr *Linker) FileByHash(hash h.Hash) (*n.File, error)

FileByHash calls NodeByHash and converts the result to a File.

func (*Linker) FilesByContents

func (lkr *Linker) FilesByContents(contents []h.Hash) (map[string]*n.File, error)

func (*Linker) HaveStagedChanges

func (lkr *Linker) HaveStagedChanges() (bool, error)

HaveStagedChanges returns true if there were changes in the staging area. If an error occurs, the first return value is undefined.

func (*Linker) Head

func (lkr *Linker) Head() (*n.Commit, error)

Head is just a shortcut for ResolveRef("HEAD").

func (*Linker) IterAll

func (lkr *Linker) IterAll(from, to *n.Commit, fn func(n.ModNode, *n.Commit) error) error

IterAll goes over all nodes in the commit range `from` until (including) `to`. Already visited nodes will not be visited again if they did not change. If `from` is nil, HEAD is assumed. If `to` is nil, INIT is assumed.

func (*Linker) ListRefs

func (lkr *Linker) ListRefs() ([]string, error)

ListRefs lists all currently known refs.

func (*Linker) LookupDirectory

func (lkr *Linker) LookupDirectory(repoPath string) (*n.Directory, error)

LookupDirectory calls LookupNode and converts the result to a Directory.

func (*Linker) LookupFile

func (lkr *Linker) LookupFile(repoPath string) (*n.File, error)

LookupFile calls LookupNode and converts the result to a file.

func (*Linker) LookupGhost

func (lkr *Linker) LookupGhost(repoPath string) (*n.Ghost, error)

LookupGhost calls LookupNode and converts the result to a ghost.

func (*Linker) LookupModNode

func (lkr *Linker) LookupModNode(repoPath string) (n.ModNode, error)

func (*Linker) LookupModNodeAt

func (lkr *Linker) LookupModNodeAt(cmt *n.Commit, repoPath string) (n.ModNode, error)

func (*Linker) LookupNode

func (lkr *Linker) LookupNode(repoPath string) (n.Node, error)

LookupNode takes the root node and tries to resolve the path from there. Deleted paths are recognized in contrast to ResolveNode. If a path does not exist NoSuchFile is returned.

func (*Linker) LookupNodeAt

func (lkr *Linker) LookupNodeAt(cmt *n.Commit, repoPath string) (n.Node, error)

TODO: Write tests for the At() variants.

func (*Linker) MakeCommit

func (lkr *Linker) MakeCommit(author string, message string) (err error)

MakeCommit creates a new full commit in the version history. The current staging commit is finalized with `author` and `message` and gets saved. A new, identical staging commit is created pointing to the root of the now new HEAD.

func (*Linker) MemIndexAdd

func (lkr *Linker) MemIndexAdd(nd n.Node)

MemIndexAdd adds `nd` to the in memory index.

func (*Linker) MemIndexClear

func (lkr *Linker) MemIndexClear()

MemIndexClear resets the memory index to zero. This should not be called mid-flight in operations, but should be okay to call between atomic operations.

func (*Linker) MemIndexPurge

func (lkr *Linker) MemIndexPurge(nd n.Node)

MemIndexPurge removes `nd` from the memory index.

func (*Linker) MemIndexSwap

func (lkr *Linker) MemIndexSwap(nd n.Node, oldHash h.Hash)

MemIndexSwap updates an entry of the in memory index, by deleting the old entry referenced by oldHash (may be nil). This is necessary to ensure that old hashes do not resolve to the new, updated instance. If the old instance is needed, it will be loaded as new instance. You should not need to call this function, except when implementing own Nodes.

func (*Linker) MemSetRoot

func (lkr *Linker) MemSetRoot(root *n.Directory)

MemSetRoot sets the current root, but does not store it yet. It's supposed to be called after in-memory modifications. Only implementors of new Nodes might need to call this function.

func (*Linker) MetadataGet

func (lkr *Linker) MetadataGet(key string) ([]byte, error)

MetadataGet retriesves a previosuly put key value pair. It will return nil if no such value could be retrieved.

func (*Linker) MetadataPut

func (lkr *Linker) MetadataPut(key string, value []byte) error

MetadataPut remembers a value persisntenly identified by `key`. It can be used as single-level key value store for user purposes.

func (*Linker) MoveEntryPoint

func (lkr *Linker) MoveEntryPoint(nd n.Node) (n.Node, MoveDir, error)

func (*Linker) MoveMapping

func (lkr *Linker) MoveMapping(cmt *n.Commit, nd n.Node) (n.Node, MoveDir, error)

MoveMapping will lookup if the node pointed to by `nd` was part of a moving operation and if so, to what node it was moved and if it was the source or the dest node.

func (*Linker) NextInode

func (lkr *Linker) NextInode() uint64

NextInode() returns a unique identifier, used to identify a single node. You should not need to call this function, except when implementing own nodes.

func (*Linker) NodeByHash

func (lkr *Linker) NodeByHash(hash h.Hash) (n.Node, error)

NodeByHash returns the node identified by hash. If no such hash could be found, nil is returned.

func (*Linker) NodeByInode

func (lkr *Linker) NodeByInode(uid uint64) (n.Node, error)

NodeByInode resolves a node by it's unique ID. It will return nil if no corresponding node was found.

func (*Linker) Owner

func (lkr *Linker) Owner() (string, error)

func (*Linker) RemoveRef

func (lkr *Linker) RemoveRef(refname string) error

func (*Linker) ResolveDirectory

func (lkr *Linker) ResolveDirectory(dirpath string) (*n.Directory, error)

ResolveDirectory calls ResolveNode and converts the result to a Directory. This only accesses nodes from the filesystem and does not differentiate between ghosts and living nodes.

func (*Linker) ResolveNode

func (lkr *Linker) ResolveNode(nodePath string) (n.Node, error)

ResolveNode resolves a path to a hash and resolves the corresponding node by calling NodeByHash(). If no node could be resolved, nil is returned. It does not matter if the node was deleted in the meantime. If so, a Ghost node is returned which stores the last known state.

func (*Linker) ResolveRef

func (lkr *Linker) ResolveRef(refname string) (n.Node, error)

ResolveRef resolves the hash associated with `refname`. If the ref could not be resolved, ErrNoSuchRef is returned. Typically, Node will be a Commit. But there are no technical restrictions on which node typ to use.

func (*Linker) Root

func (lkr *Linker) Root() (*n.Directory, error)

Root returns the current root directory of CURR. It is never nil when err is nil.

func (*Linker) SaveRef

func (lkr *Linker) SaveRef(refname string, nd n.Node) error

SaveRef stores a reference to `nd` persistently. The caller is responsbiel to ensure that the node is already in the blockstore, otherwise it won't be resolvable.

func (*Linker) SetMergeMarker

func (lkr *Linker) SetMergeMarker(with string, remoteHead h.Hash) error

SetMergeMarker sets the current status to be a merge commit. Note that this function only will have a result when MakeCommit() is called afterwards. Otherwise, the changes will not be written to disk.

func (*Linker) SetOwner

func (lkr *Linker) SetOwner(owner string) error

func (*Linker) StageNode

func (lkr *Linker) StageNode(nd n.Node) (err error)

StageNode inserts a modified node to the staging area, making sure the modification is persistent and part of the staging commit. All parent directories of the node in question will be staged automatically. If there was no modification it will be a (quite expensive) NOOP.

func (*Linker) Status

func (lkr *Linker) Status() (cmt *n.Commit, err error)

Status returns the current staging commit. It is never nil, unless err is nil.

type MoveDir

type MoveDir int

func (MoveDir) Invert

func (md MoveDir) Invert() MoveDir

func (MoveDir) String

func (md MoveDir) String() string

Jump to

Keyboard shortcuts

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