Documentation ¶
Index ¶
- Constants
- Variables
- func AssertDir(t *testing.T, lkr *Linker, path string, shouldExist bool)
- func Copy(lkr *Linker, nd n.ModNode, dstPath string) (newNode n.ModNode, err error)
- func Log(lkr *Linker, fn func(cmt *n.Commit) error) error
- func Mkdir(lkr *Linker, repoPath string, createParents bool) (dir *n.Directory, err error)
- func Move(lkr *Linker, nd n.ModNode, dstPath string) error
- func MustCommit(t *testing.T, lkr *Linker, msg string) *n.Commit
- func MustCommitIfPossible(t *testing.T, lkr *Linker, msg string) *n.Commit
- func MustLookupDirectory(t *testing.T, lkr *Linker, path string) *n.Directory
- func MustMkdir(t *testing.T, lkr *Linker, repoPath string) *n.Directory
- func MustModify(t *testing.T, lkr *Linker, file *n.File, seed int)
- func MustMove(t *testing.T, lkr *Linker, nd n.ModNode, destPath string) n.ModNode
- func MustRemove(t *testing.T, lkr *Linker, nd n.ModNode) n.ModNode
- func MustTouch(t *testing.T, lkr *Linker, touchPath string, seed byte) *n.File
- func MustTouchAndCommit(t *testing.T, lkr *Linker, path string, seed byte) (*n.File, *n.Commit)
- func Remove(lkr *Linker, nd n.ModNode, createGhost, force bool) (parentDir *n.Directory, ghost *n.Ghost, err error)
- func Stage(lkr *Linker, repoPath string, contentHash, backendHash h.Hash, size uint64, ...) (file *n.File, err error)
- func StageFromFileNode(lkr *Linker, f *n.File) (*n.File, error)
- func WithDummyKv(t *testing.T, fn func(kv db.Database))
- func WithDummyLinker(t *testing.T, fn func(lkr *Linker))
- func WithLinkerPair(t *testing.T, fn func(lkrSrc, lkrDst *Linker))
- func WithReloadingLinker(t *testing.T, fn1 func(lkr *Linker), fn2 func(lkr *Linker))
- type GarbageCollector
- type Linker
- func (lkr *Linker) AddMoveMapping(fromInode, toInode uint64) (err error)
- func (lkr *Linker) Atomic(fn func() (bool, error)) (err error)
- func (lkr *Linker) AtomicWithBatch(fn func(batch db.Batch) (bool, error)) (err error)
- func (lkr *Linker) CheckoutCommit(cmt *n.Commit, force bool) error
- func (lkr *Linker) CommitByHash(hash h.Hash) (*n.Commit, error)
- func (lkr *Linker) CommitByIndex(index int64) (*n.Commit, error)
- func (lkr *Linker) DirectoryByHash(hash h.Hash) (*n.Directory, error)
- func (lkr *Linker) ExpandAbbrev(abbrev string) (h.Hash, error)
- func (lkr *Linker) FileByHash(hash h.Hash) (*n.File, error)
- func (lkr *Linker) FilesByContents(contents []h.Hash) (map[string]*n.File, error)
- func (lkr *Linker) HaveStagedChanges() (bool, error)
- func (lkr *Linker) Head() (*n.Commit, error)
- func (lkr *Linker) IterAll(from, to *n.Commit, fn func(n.ModNode, *n.Commit) error) error
- func (lkr *Linker) KV() db.Database
- func (lkr *Linker) ListRefs() ([]string, error)
- func (lkr *Linker) LookupDirectory(repoPath string) (*n.Directory, error)
- func (lkr *Linker) LookupFile(repoPath string) (*n.File, error)
- func (lkr *Linker) LookupGhost(repoPath string) (*n.Ghost, error)
- func (lkr *Linker) LookupModNode(repoPath string) (n.ModNode, error)
- func (lkr *Linker) LookupModNodeAt(cmt *n.Commit, repoPath string) (n.ModNode, error)
- func (lkr *Linker) LookupNode(repoPath string) (n.Node, error)
- func (lkr *Linker) LookupNodeAt(cmt *n.Commit, repoPath string) (n.Node, error)
- func (lkr *Linker) MakeCommit(author string, message string) error
- func (lkr *Linker) MemIndexAdd(nd n.Node, updatePathIndex bool)
- func (lkr *Linker) MemIndexClear()
- func (lkr *Linker) MemIndexPurge(nd n.Node)
- func (lkr *Linker) MemIndexSwap(nd n.Node, oldHash h.Hash, updatePathIndex bool)
- func (lkr *Linker) MemSetRoot(root *n.Directory)
- func (lkr *Linker) MetadataGet(key string) ([]byte, error)
- func (lkr *Linker) MetadataPut(key string, value []byte) error
- func (lkr *Linker) MoveEntryPoint(nd n.Node) (n.Node, MoveDir, error)
- func (lkr *Linker) MoveMapping(cmt *n.Commit, nd n.Node) (n.Node, MoveDir, error)
- func (lkr *Linker) NextInode() uint64
- func (lkr *Linker) NodeByHash(hash h.Hash) (n.Node, error)
- func (lkr *Linker) NodeByInode(uid uint64) (n.Node, error)
- func (lkr *Linker) Owner() (string, error)
- func (lkr *Linker) RemoveRef(refname string) error
- func (lkr *Linker) ResolveDirectory(dirpath string) (*n.Directory, error)
- func (lkr *Linker) ResolveNode(nodePath string) (n.Node, error)
- func (lkr *Linker) ResolveRef(refname string) (n.Node, error)
- func (lkr *Linker) Root() (*n.Directory, error)
- func (lkr *Linker) SaveRef(refname string, nd n.Node) error
- func (lkr *Linker) SetMergeMarker(with string, remoteHead h.Hash) error
- func (lkr *Linker) SetOwner(owner string) error
- func (lkr *Linker) StageNode(nd n.Node) error
- func (lkr *Linker) Status() (*n.Commit, error)
- type MoveDir
Constants ¶
const ( // MoveDirUnknown should only be used for init purposes. MoveDirUnknown = iota // MoveDirSrcToDst means that this file was moved from source to dest. // (Therefore it is the new destination file and probably not a ghost) MoveDirSrcToDst // MoveDirDstToSrc means that this place was moved somewhere else. // (Therefore it is a likely a ghost and the new file lives somewhere else) MoveDirDstToSrc // MoveDirNone tells us that this file did not move. MoveDirNone )
Variables ¶
var ( // ErrIsGhost is returned by Remove() when calling it on a ghost. ErrIsGhost = errors.New("Is a ghost") )
Functions ¶
func Log ¶
Log will call `fn` on every commit we currently have, starting with the most current one (CURR, then HEAD, ...). If `fn“ will return an error, the iteration is being stopped.
func Mkdir ¶
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 MustCommit ¶
MustCommit commits the current state with `msg`.
func MustCommitIfPossible ¶
MustCommitIfPossible with is like MustCommit, but allows empty changesets.
func MustLookupDirectory ¶
MustLookupDirectory loads an existing dir or fails.
func MustModify ¶
MustModify changes the content of an existing node.
func MustRemove ¶
MustRemove removes the node `nd` or fails.
func MustTouch ¶
MustTouch creates a new node at `touchPath` and sets its content hash to a hash derived from `seed`.
func MustTouchAndCommit ¶
MustTouchAndCommit is a combined MustTouch and MustCommit.
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, contentHash, backendHash h.Hash, size uint64, key []byte) (file *n.File, err error)
Stage adds a file to brigs DAG.
func StageFromFileNode ¶
StageFromFileNode is a convinience helper that will call Stage() with all necessary params from `f`.
func WithDummyKv ¶
WithDummyKv creates a testing key value store and passes it to `fn`.
func WithDummyLinker ¶
WithDummyLinker creates a testing linker and passes it to `fn`.
func WithLinkerPair ¶
WithLinkerPair creates two linkers, useful for testing syncing.
func WithReloadingLinker ¶
WithReloadingLinker creates a testing linker and passes it to `fn1`. It then closes the linker and lets it load a second time and passes it to `fn2`. This is useful to test persistency issues.
Types ¶
type GarbageCollector ¶
type GarbageCollector struct {
// contains filtered or unexported fields
}
GarbageCollector implements a small mark & sweep garbage collector. It exists more for the sake of fault tolerance than it being an essential part of brig. This is different from the ipfs garbage collector.
func NewGarbageCollector ¶
NewGarbageCollector will return a new GC, operating on `lkr` and `kv`. It will call `kc` on every collected node.
func (*GarbageCollector) Run ¶
func (gc *GarbageCollector) Run(allObjects bool) error
Run will trigger a GC run. If `allObjects` is false, only the staging commit will be checked. Otherwise all objects in the key value store.
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 ¶
NewLinker returns a new lkr, ready to use. It assumes the key value store is working and does no check on this.
func (*Linker) AddMoveMapping ¶
AddMoveMapping takes note that the the node with `fromInode` has been moved to `toInode` in the staging commit.
func (*Linker) Atomic ¶
Atomic is like AtomicWithBatch but does not require using a batch. Use this for read-only operations. It's only syntactic sugar though.
func (*Linker) AtomicWithBatch ¶
AtomicWithBatch will execute `fn` in one transaction. If anything goes wrong (i.e. `fn` returns an error)
func (*Linker) CheckoutCommit ¶
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 ¶
CommitByHash lookups a commit by it's hash. If the commit could not be found, nil is returned.
func (*Linker) CommitByIndex ¶
CommitByIndex returns the commit referenced by `index`. `0` will return the very first commit. Negative numbers will yield a ErrNoSuchKey error.
func (*Linker) DirectoryByHash ¶
DirectoryByHash calls NodeByHash and attempts to convert it to a Directory as convinience.
func (*Linker) ExpandAbbrev ¶
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 ¶
FileByHash calls NodeByHash and converts the result to a File.
func (*Linker) FilesByContents ¶
FilesByContents checks what files are associated with the content hashes in `contents`. It returns a map of content hash b58 to file. This method is quite heavy and should not be used in loops. There is room for optimizations.
func (*Linker) HaveStagedChanges ¶
HaveStagedChanges returns true if there were changes in the staging area. If an error occurs, the first return value is undefined.
func (*Linker) IterAll ¶
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) KV ¶ added in v0.2.0
KV returns the key value store passed when constructing the linker.
func (*Linker) LookupDirectory ¶
LookupDirectory calls LookupNode and converts the result to a Directory.
func (*Linker) LookupFile ¶
LookupFile calls LookupNode and converts the result to a file.
func (*Linker) LookupGhost ¶
LookupGhost calls LookupNode and converts the result to a ghost.
func (*Linker) LookupModNode ¶
LookupModNode is like LookupNode but returns a readily cast ModNode.
func (*Linker) LookupModNodeAt ¶
LookupModNodeAt is like LookupNodeAt but with readily cast type.
func (*Linker) LookupNode ¶
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 ¶
LookupNodeAt works like LookupNode but returns the node at the state of `cmt`.
func (*Linker) MakeCommit ¶
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.
If nothing changed since the last call to MakeCommit, it will return ErrNoChange, which can be reacted upon.
func (*Linker) MemIndexAdd ¶
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 ¶
MemIndexPurge removes `nd` from the memory index.
func (*Linker) MemIndexSwap ¶
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 ¶
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 ¶
MetadataGet retriesves a previously put key value pair. It will return nil if no such value could be retrieved.
func (*Linker) MetadataPut ¶
MetadataPut remembers a value persisntenly identified by `key`. It can be used as single-level key value store for user purposes.
func (*Linker) MoveEntryPoint ¶
MoveEntryPoint tells us if a node participated in a move. If so, the new node and the corresponding move direction is returned.
func (*Linker) MoveMapping ¶
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 ¶
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 ¶
NodeByHash returns the node identified by hash. If no such hash could be found, nil is returned.
func (*Linker) NodeByInode ¶
NodeByInode resolves a node by it's unique ID. It will return nil if no corresponding node was found.
func (*Linker) ResolveDirectory ¶
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 ¶
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 ¶
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. NOTE: ResolveRef("HEAD") != ResolveRef("head") due to case.
func (*Linker) Root ¶
Root returns the current root directory of CURR. It is never nil when err is nil.
func (*Linker) SaveRef ¶
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 ¶
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.