Documentation ¶
Index ¶
Constants ¶
const ( //PathSeparator is used to join path into database keys. Bolt stores values in a bucket in byte-order, choosing a unicode code point all the way at the end allows us to make assumptions when we use a cursor to iterate over directory entries PathSeparator = "\uFFFF" //PathPrintSeparator is used instead of the character above to print a path PathPrintSeparator = "/" //RootBasename is returned when the root is asked for its basename RootBasename = PathSeparator )
Variables ¶
var ( //LayerBucketName is the name of the bucket that will hold the layers LayerBucketName = []byte("Layer") //NodeBucketName is the name of the bucket that will hold the nodes NodeBucketName = []byte("Node") //ChunkBucketName is the name of the bucket that will hold the chunks ChunkBucketName = []byte("Chunk") )
var ( //ErrSerialize is returned when we couldnt serialize ErrSerialize = errors.New("failed to serialize") //ErrDeserialize is returned when we couldnt deserialize ErrDeserialize = errors.New("failed to deserialize") )
var (
//ChunkOffsetSeparator separates a node key from a chunk offset
ChunkOffsetSeparator = ":"
)
var ( // ErrInvalidPath is returned when no valid filename can be created from path components ErrInvalidPath = errors.New("invalid path components") )
var ( //Root is a path with zero components: len(Root) = 0 Root = P{} )
var ( //ZeroKey is a empty key ZeroKey = K{} )
Functions ¶
This section is empty.
Types ¶
type BranchWriter ¶
type BranchWriter struct {
// contains filtered or unexported fields
}
BranchWriter acts as a handle for modifying a branch Node in our hierarchy. Upon initiating, the key of the node will be determined although an actual value for this key will only be written upon committing. Operations on the node can span different database transactions.
func NewBranchWriter ¶
NewBranchWriter allow writing a (new) branch node while merging children 'mChildren' and chunks 'mChunks' with the existing node at key 'nodeK'.
When the node's key 'k' is nil a new node is instead created with just the provided children 'mChildren' and chunks 'mChunks'
When the key of a merged child is a ZeroKey the child acts as a tombstone and is removed from the new node instead.
When the first new chunk is mapped to a lower file offset then existing chunks only chunks positioned lower than the new offset are copied over. If the first merged chunk has an offset of zero we are rewriting the node completely, and if then the first chunk has a zerokey we are truncating the node's content.
func (*BranchWriter) Commit ¶
func (nw *BranchWriter) Commit(tx *bolt.Tx, n *Node) (err error)
Commit the branch node with its, merged children while serialize file information and calculate the final checksum, the size field 'S' and modTime filed 'T' will be set by the commit.
func (*BranchWriter) WriteChild ¶
WriteChild will write a reference to child node at 'k' in the branch node
type Layer ¶
type Layer struct {
Root *Node //the top node
}
A Layer represents a point-in-time snapshot of a node tree with file chunks. The fileystem is always created with a specific "top" layer to which new data can be written.
type LayerFS ¶
type LayerFS struct {
// contains filtered or unexported fields
}
LayerFS is an userland, append only, deduplicated filesystem build on top of boltdb
type Node ¶
type Node struct { N string //base name T time.Time //mod time S int64 //size M os.FileMode //portable mode bits }
A Node can either contain links to other nodes (a directory) or to opaque content chunks when representing a file. Node implements os.FileInfo. It is stores as a header under the node's key (hash), directly followed by a list of its nested values (other nodes for branches, chunk offsets for a leaf): | Key | Data | Comment | 00000001 : <CHECKSUM>{ ... } #file info, checksum as prefix 00000001/a.txt : 00000002 #to another node 00000001/b.txt : 00000003 #to another node 00000001:0 : 2511E0F94...979AF0F #chunk at file offset 0 00000001:332111 : 2511E0F94...979AF0F #chunk at offset 332111
func (*Node) IsDir ¶
IsDir reports whether m describes a directory. That is, it tests for the ModeDir bit being set in m.
type P ¶
type P []string
P describes a platform agnostic path on the file system and is stored as a slice of path components
func (P) Parent ¶
Parent returns a path that refers to a parent, if the current path is the root the root is still returned