mount

package
v0.0.0-...-98f8d24 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound = os.ErrNotExist
	ErrFileFound    = os.ErrExist
	ErrNoPermission = os.ErrPermission
	ErrNotFolder    = errors.New("listing a non-folder")
	ErrOther        = errors.New("unknown error")
)
View Source
var MountErrMsg = [...]string{
	MountErrorLeafHasChild: "mount leaf not empty",
	MountErrorPathHasLeaf:  "mount path contains leaf",
	MountErrorLeafExists:   "mount leaf exists",
	MountErrorRootIsNil:    "mount called with (root *node) == nil",
}

Functions

This section is empty.

Types

type File

type File struct {
	Name        string
	Size        int64
	LastModify  time.Time
	IsDirectory bool // True for a directory, false for a file
}

type MountErrType

type MountErrType int
const (
	MountErrorLeafHasChild MountErrType = iota
	MountErrorPathHasLeaf
	MountErrorLeafExists
	MountErrorRootIsNil
)

type MountError

type MountError struct {
	MountPath, NodeName string
	Type                MountErrType
}

MountError indicates errors arising when mounting a node.

func (*MountError) Error

func (err *MountError) Error() string

type Node

type Node interface {
	// Name returns the name to be printed for a human reader to identify.
	Name() string
	List(folder string) ([]File, error) // List lists the files under the node.
	Stat(file string) (File, error)     // Stat stats a single file under the node.

	// ReadFile returns a io.Reader created by reading the file
	// under this directory, possibly transversing through other
	// sub-directories.
	//
	// If the returned Reader satifies io.Closer, the file is
	// closed after use.
	ReadFile(file string) (io.Reader, error)

	// WriteFile returns a io.Writer that stores the file under
	// this directory, rewriting existing one if present.
	//
	// If the returned Writer satifies io.Closer, the file is
	// closed after use.
	WriteFile(file string) (io.Writer, error)

	// AppendFile returns a io.Writer that stores the file under
	// this directory, appending existing one if present.
	//
	// If the returned Writer satifies io.Closer, the file is
	// closed after use.
	AppendFile(file string) (io.Writer, error)

	// DeleteFile deletes a file at the given location, but
	// does nothing if the file is a directory.
	DeleteFile(file string) error

	// MakeDirectory makes a new directory (or directories) under
	// this node.
	MakeDirectory(dir string) error

	// RemoveDirectory deletes a directory at the given location, but
	// does nothing if the file is not a directory.
	RemoveDirectory(dir string) error
}

Node is a node (folder) in the virtual filesystem. The file/dir parameters are relative paths, but with no "./" at the beginning, or other relative marks like "..".

The Node interface methods must be safe to call from multiple goroutines.

type NodeSysFolder

type NodeSysFolder struct {
	// Path is the system filesystem path.
	Path string
	// NodeName is the name of the folder in the mount. It is not reflected
	// in the virtual filesystem.
	NodeName string
}

NodeSysFolder is a virtual filesystem node mounted from a system filesystem folder.

func (*NodeSysFolder) AppendFile

func (n *NodeSysFolder) AppendFile(file string) (io.Writer, error)

func (*NodeSysFolder) DeleteFile

func (n *NodeSysFolder) DeleteFile(file string) error

func (*NodeSysFolder) List

func (n *NodeSysFolder) List(folder string) (files []File, err error)

func (*NodeSysFolder) MakeDirectory

func (n *NodeSysFolder) MakeDirectory(dir string) error

func (*NodeSysFolder) Name

func (n *NodeSysFolder) Name() string

func (*NodeSysFolder) ReadFile

func (n *NodeSysFolder) ReadFile(file string) (io.Reader, error)

func (*NodeSysFolder) RemoveDirectory

func (n *NodeSysFolder) RemoveDirectory(dir string) error

func (*NodeSysFolder) Stat

func (n *NodeSysFolder) Stat(file string) (result File, err error)

func (*NodeSysFolder) WriteFile

func (n *NodeSysFolder) WriteFile(file string) (io.Writer, error)

type NodeTree

type NodeTree node

NodeTree is a root node for containing a mount tree hierachy. It should also satsify Node, but please don't mount it onto another tree. Weird things might happen.

func NewNodeTree

func NewNodeTree() *NodeTree

func NewNodeTreeFromFile

func NewNodeTreeFromFile(filename string) (t *NodeTree, err error)

NewNodeTreeFromFile creates a new node tree, with multiple system folder mounted, reading from a listing in the file filename.

The file is composed of lines that are empty, begin with #, or are of the following format:

[VFS mount target path]:[System folder path]

A TVFS path does not have colons so the first colon ends the target.

func (*NodeTree) AppendFile

func (n *NodeTree) AppendFile(file string) (io.Writer, error)

func (*NodeTree) DeleteFile

func (n *NodeTree) DeleteFile(file string) error

func (*NodeTree) List

func (n *NodeTree) List(folder string) (files []File, err error)

func (*NodeTree) MakeDirectory

func (n *NodeTree) MakeDirectory(dir string) error

func (*NodeTree) Mount

func (root *NodeTree) Mount(path string, n Node) error

Mount mounts the node at the path in the VFS rooted at root.

It must not be called concurrently with other access functions of *NodeTree.

func (*NodeTree) Name

func (*NodeTree) Name() string

func (*NodeTree) ReadFile

func (n *NodeTree) ReadFile(file string) (io.Reader, error)

func (*NodeTree) RemoveDirectory

func (n *NodeTree) RemoveDirectory(dir string) error

func (*NodeTree) Stat

func (n *NodeTree) Stat(file string) (File, error)

func (*NodeTree) WriteFile

func (n *NodeTree) WriteFile(file string) (io.Writer, error)

Jump to

Keyboard shortcuts

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