mem

package
v0.0.0-...-9ecad67 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("method not implemented for the node type")
)

Functions

func Serialize

func Serialize(root *Dir, writer io.Writer) error

Types

type Context

type Context struct {
	Notifier Notifier
}

Shared context of all nodes

type Dir

type Dir struct {
	NodeCommon

	// Obtained after resolution
	Nodes map[string]Node
}

func Deserialize

func Deserialize(ctx *Context, reader io.Reader, external bool) (*Dir, error)

func NewDir

func NewDir(ctx *Context, id string) *Dir

func NewDirWithChildren

func NewDirWithChildren(ctx *Context, id string, nodes map[string]Node) *Dir

func NewExternalDir

func NewExternalDir(ctx *Context, id string, d driver.Driver, r driver.Reference) *Dir

func (*Dir) AddNode

func (n *Dir) AddNode(name string, node tree.Node, overwrite bool) error

func (*Dir) CreateNode

func (n *Dir) CreateNode(name string, nodeType tree.NodeType) (tree.Node, error)
func (n *Dir) CreateSymlink(name string, target string) (tree.Node, error)

func (*Dir) DeleteNode

func (n *Dir) DeleteNode(name string) error

func (*Dir) GetNodeByName

func (n *Dir) GetNodeByName(name string) (tree.Node, error)

func (*Dir) GetNodes

func (n *Dir) GetNodes() (map[string]tree.Node, error)

func (*Dir) Pack

func (n *Dir) Pack(outputChan chan *NodeData) error

func (*Dir) Type

func (n *Dir) Type() tree.NodeType

type DirEntry

type DirEntry struct {
	Name         string
	Id           string
	NodeType     tree.NodeType
	IsExecutable bool
	IsExternal   bool
}

Encode directoy entries. Stored as JSON in blob.

type ExternalReference

type ExternalReference struct {
	DriverName       string
	EncodedReference string
}

Encode an external node. Stored as JSON in blob.

type File

type File struct {
	NodeCommon
	IsExecutable bool

	// Obtained after resolution
	Data []byte
}

func NewExternalFile

func NewExternalFile(ctx *Context, id string, isExecutable bool, d driver.Driver, r driver.Reference) *File

New external file node with given driver and reference

func NewFile

func NewFile(ctx *Context, id string, isExecutable bool) *File

New file node with empty data

func NewFileWithData

func NewFileWithData(ctx *Context, id string, isExecutable bool, data []byte) *File

New file node with given data

func (*File) GetExecutable

func (n *File) GetExecutable() (bool, error)

func (*File) GetSize

func (n *File) GetSize() (uint64, error)

func (*File) Pack

func (n *File) Pack(outputChan chan *NodeData) error

func (*File) Read

func (n *File) Read(offset uint64, size uint32) ([]byte, error)

func (*File) SetExecutable

func (n *File) SetExecutable(executable bool) error

func (*File) Truncate

func (n *File) Truncate(size uint64) error

func (*File) Type

func (n *File) Type() tree.NodeType

func (*File) Write

func (n *File) Write(offset uint64, data []byte) (uint32, error)

type Node

type Node interface {
	tree.Node

	Lock()
	Unlock()

	RLock()
	RUnlock()

	GetParent() Node
	SetParent(node Node)

	GetResolved() bool
	SetResolved(resolved bool)

	SetDriver(driver.Driver)
	SetReference(driver.Reference)

	// This method needs to be called with read lock held, similar to other
	// methods that access the internal state.
	Pack(outputChan chan *NodeData) error
}

type NodeCommon

type NodeCommon struct {
	NodeId       string
	Parent       Node
	CreatedTime  time.Time
	ModifiedTime time.Time

	// External bit (this is true if a node used to be external, even
	// after its resolution)
	External  bool
	Driver    driver.Driver
	Reference driver.Reference

	Resolved bool

	Context *Context

	Mutex sync.RWMutex
}

Mem-cached node implementation with optional persistent backend.

func (*NodeCommon) AddNode

func (n *NodeCommon) AddNode(name string, node tree.Node, overwrite bool) error

func (*NodeCommon) CreateNode

func (n *NodeCommon) CreateNode(name string, nodeType tree.NodeType) (tree.Node, error)
func (n *NodeCommon) CreateSymlink(name string, target string) (tree.Node, error)

func (*NodeCommon) DeleteNode

func (n *NodeCommon) DeleteNode(name string) error

func (*NodeCommon) GetCreationTime

func (n *NodeCommon) GetCreationTime() (time.Time, error)

func (*NodeCommon) GetExecutable

func (n *NodeCommon) GetExecutable() (bool, error)

func (*NodeCommon) GetModTime

func (n *NodeCommon) GetModTime() (time.Time, error)

func (*NodeCommon) GetNodeByName

func (n *NodeCommon) GetNodeByName(name string) (tree.Node, error)

func (*NodeCommon) GetNodes

func (n *NodeCommon) GetNodes() (map[string]tree.Node, error)

func (*NodeCommon) GetParent

func (n *NodeCommon) GetParent() Node

func (*NodeCommon) GetResolved

func (n *NodeCommon) GetResolved() bool

func (*NodeCommon) GetSize

func (n *NodeCommon) GetSize() (uint64, error)

func (*NodeCommon) Id

func (n *NodeCommon) Id() string

func (*NodeCommon) IsReadOnly

func (n *NodeCommon) IsReadOnly() bool

func (*NodeCommon) Lock

func (n *NodeCommon) Lock()

func (*NodeCommon) Pack

func (n *NodeCommon) Pack(outputChan chan *NodeData) error

func (*NodeCommon) RLock

func (n *NodeCommon) RLock()

func (*NodeCommon) RUnlock

func (n *NodeCommon) RUnlock()

func (*NodeCommon) Read

func (n *NodeCommon) Read(offset uint64, size uint32) ([]byte, error)
func (n *NodeCommon) ReadLink() (string, error)

func (*NodeCommon) SetDriver

func (n *NodeCommon) SetDriver(d driver.Driver)

func (*NodeCommon) SetExecutable

func (n *NodeCommon) SetExecutable(executable bool) error

func (*NodeCommon) SetParent

func (n *NodeCommon) SetParent(node Node)

func (*NodeCommon) SetReference

func (n *NodeCommon) SetReference(ref driver.Reference)

func (*NodeCommon) SetResolved

func (n *NodeCommon) SetResolved(resolved bool)

func (*NodeCommon) Truncate

func (n *NodeCommon) Truncate(size uint64) error

func (*NodeCommon) Unlock

func (n *NodeCommon) Unlock()

func (*NodeCommon) Write

func (n *NodeCommon) Write(offset uint64, data []byte) (uint32, error)

type NodeData

type NodeData struct {
	Id   string
	Data []byte
}

Serialized format of a node. Used to communicate with the persistent backend.

func (*NodeData) UnpackDir

func (nd *NodeData) UnpackDir(ctx *Context, external bool, nodeDataMap map[string]*NodeData) (*Dir, error)

func (*NodeData) UnpackFile

func (nd *NodeData) UnpackFile(ctx *Context, external bool, isExecutable bool) (*File, error)
func (nd *NodeData) UnpackSymlink(ctx *Context, external bool) (*Symlink, error)

type Notifier

type Notifier interface {
	NodeChanged(id string)
}

Notifier describes an optional entity to each node for it to notify certain events. The user of this library can implement its own notifier to capture and process those events.

type Symlink struct {
	NodeCommon

	// Obtained after resolution
	Target string
}
func NewExternalSymlink(ctx *Context, id string, d driver.Driver, r driver.Reference) *Symlink
func NewSymlink(ctx *Context, id string, target string) *Symlink

func (*Symlink) Pack

func (n *Symlink) Pack(outputChan chan *NodeData) error
func (n *Symlink) ReadLink() (string, error)

func (*Symlink) Type

func (n *Symlink) Type() tree.NodeType

Jump to

Keyboard shortcuts

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