rufs: devt.de/krotik/rufs Index | Files | Directories

package rufs

import "devt.de/krotik/rufs"

Package rufs contains the main API to Rufs.

Rufs is organized as a collection of branches. Each branch represents a physical file system structure which can be queried and updated by an authorized client.

On the client side one or several branches are organized into a tree. The single branches can overlay each other. For example:

Branch A /foo/A /foo/B /bar/C

Branch B /foo/C /test/D

Tree 1 /myspace => Branch A, Branch B

Accessing tree with: /myspace/foo/A gets file /foo/A from Branch A while /myspace/foo/C gets file /foo/C from Branch B

Write operations go only to branches which are mapped as writing branches and who accept them (i.e. are not set to readonly on the side of the branch).

Index

Package Files

branch.go fileinfo.go tree.go tree_item.go util.go

Constants

const (
    ItemOpAction  = "itemop_action"  // ItemOp action
    ItemOpName    = "itemop_name"    // Item name
    ItemOpNewName = "itemop_newname" // New item name
)

ItemOp parameter

const (
    ItemOpActRename = "rename" // Rename a file or directory
    ItemOpActDelete = "delete" // Delete a file or directory
    ItemOpActMkDir  = "mkdir"  // Create a directory
)

ItemOp actions

const (
    ParamAction    = "a" // Requested action
    ParamPath      = "p" // Path string
    ParamPattern   = "x" // Pattern string
    ParamRecursive = "r" // Recursive flag
    ParamChecksums = "c" // Checksum flag
    ParamOffset    = "o" // Offset parameter
    ParamSize      = "s" // Size parameter
)

Meta parameter

const (
    OpDir    = "dir"    // Read the contents of a path
    OpRead   = "read"   // Read the contents of a file
    OpWrite  = "write"  // Read the contents of a file
    OpItemOp = "itemop" // File or directory operation
)

Possible actions

const (
    SyncCreateDirectory = "Create directory"
    SyncCopyFile        = "Copy file"
    SyncRemoveDirectory = "Remove directory"
    SyncRemoveFile      = "Remove file"
)

Sync operations

Variables

var DefaultReadBufferSize = 1024 * 16

DefaultReadBufferSize is the default size for file reading.

func DirResultToString Uses

func DirResultToString(paths []string, infos [][]os.FileInfo) string

DirResultToString formats a given Dir result into a human-readable string.

func IsEOF Uses

func IsEOF(err error) bool

IsEOF tests if the given error is an EOF error.

func WrapFileInfo Uses

func WrapFileInfo(path string, i os.FileInfo) os.FileInfo

WrapFileInfo wraps a single os.FileInfo object in a serializable FileInfo.

func WrapFileInfos Uses

func WrapFileInfos(path string, is []os.FileInfo) []os.FileInfo

WrapFileInfos wraps a list of os.FileInfo objects into a list of serializable FileInfo objects. This function will modify the given list.

type Branch Uses

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

Branch models a single exported branch in Rufs.

func NewBranch Uses

func NewBranch(cfg map[string]interface{}, cert *tls.Certificate) (*Branch, error)

NewBranch returns a new exported branch.

func (*Branch) Dir Uses

func (b *Branch) Dir(spath string, pattern string, recursive bool, checksums bool) ([]string, [][]os.FileInfo, error)

Dir returns file listings matching a given pattern of one or more directories. The contents of the given path is returned along with checksums if the checksum flag is specified. Optionally, also the contents of all subdirectories can be returned if the recursive flag is set. The return values is a list of traversed directories (platform-agnostic) and their corresponding contents.

func (*Branch) IsReadOnly Uses

func (b *Branch) IsReadOnly() bool

IsReadOnly returns if this branch is read-only.

func (*Branch) ItemOp Uses

func (b *Branch) ItemOp(spath string, opdata map[string]string) (bool, error)

ItemOp executes a file or directory specific operation which can either succeed or fail (e.g. rename or delete). Actions and parameters should be given in the opdata map.

func (*Branch) Name Uses

func (b *Branch) Name() string

Name returns the name of the branch.

func (*Branch) ReadFile Uses

func (b *Branch) ReadFile(spath string, p []byte, offset int64) (int, error)

ReadFile reads up to len(p) bytes into p from the given offset. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.

func (*Branch) ReadFileToBuffer Uses

func (b *Branch) ReadFileToBuffer(spath string, buf io.Writer) error

ReadFileToBuffer reads a complete file into a given buffer which implements io.Writer.

func (*Branch) SSLFingerprint Uses

func (b *Branch) SSLFingerprint() string

SSLFingerprint returns the SSL fingerprint of the branch.

func (*Branch) Shutdown Uses

func (b *Branch) Shutdown() error

Shutdown shuts the branch down.

func (*Branch) WriteFile Uses

func (b *Branch) WriteFile(spath string, p []byte, offset int64) (int, error)

WriteFile writes p into the given file from the given offset. It returns the number of written bytes and any error encountered.

func (*Branch) WriteFileFromBuffer Uses

func (b *Branch) WriteFileFromBuffer(spath string, buf io.Reader) error

WriteFileFromBuffer writes a complete file from a given buffer which implements io.Reader.

type FileInfo Uses

type FileInfo struct {
    FiName     string      // Base name
    FiSize     int64       // Size in bytes
    FiMode     os.FileMode // File mode bits
    FiModTime  time.Time   // Modification time
    FiChecksum string      // Checksum of files
    // contains filtered or unexported fields
}

FileInfo implements os.FileInfo in an platform-agnostic way

func (*FileInfo) Checksum Uses

func (rfi *FileInfo) Checksum() string

Checksum returns the checksum of this file. May be an empty string if it was not calculated.

func (*FileInfo) IsDir Uses

func (rfi *FileInfo) IsDir() bool

IsDir returns if this is a directory.

func (*FileInfo) ModTime Uses

func (rfi *FileInfo) ModTime() time.Time

ModTime returns the modification time.

func (*FileInfo) Mode Uses

func (rfi *FileInfo) Mode() os.FileMode

Mode returns the file mode bits.

func (*FileInfo) Name Uses

func (rfi *FileInfo) Name() string

Name returns the base name.

func (*FileInfo) Size Uses

func (rfi *FileInfo) Size() int64

Size returns the length in bytes.

func (*FileInfo) String Uses

func (rfi *FileInfo) String() string

func (*FileInfo) Sys Uses

func (rfi *FileInfo) Sys() interface{}

Sys should return the underlying data source but will always return nil for FileInfo nodes.

type Tree Uses

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

Tree models a Rufs client which combines several branches.

func NewTree Uses

func NewTree(cfg map[string]interface{}, cert *tls.Certificate) (*Tree, error)

NewTree creates a new tree.

func (*Tree) ActiveBranches Uses

func (t *Tree) ActiveBranches() ([]string, []string)

ActiveBranches returns a list of all known active branches and their fingerprints.

func (*Tree) AddBranch Uses

func (t *Tree) AddBranch(branchName string, branchRPC string, branchFingerprint string) error

AddBranch adds a branch to the tree.

func (*Tree) AddMapping Uses

func (t *Tree) AddMapping(dir, branchName string, writable bool) error

AddMapping adds a mapping from tree path to a branch.

func (*Tree) Config Uses

func (t *Tree) Config() string

Config returns the current tree configuration as a JSON string.

func (*Tree) Copy Uses

func (t *Tree) Copy(src []string, dst string,
    updFunc func(file string, writtenBytes, totalBytes, currentFile, totalFiles int64)) error

Copy is a general purpose copy function which creates files and directories. Destination must be a directory. A non-existing destination directory will be created.

func (*Tree) CopyFile Uses

func (t *Tree) CopyFile(srcPath, dstPath string, updFunc func(writtenBytes int)) error

CopyFile copies a given file using a simple io.Pipe.

func (*Tree) Dir Uses

func (t *Tree) Dir(dir string, pattern string, recursive bool, checksums bool) ([]string, [][]os.FileInfo, error)

Dir returns file listings matching a given pattern of one or more directories. The contents of the given path is returned. Optionally, also the contents of all subdirectories can be returned if the recursive flag is set. The return values is a list of traversed directories and their corresponding contents.

func (*Tree) ItemOp Uses

func (t *Tree) ItemOp(dir string, opdata map[string]string) (bool, error)

ItemOp executes a file or directory specific operation which can either succeed or fail (e.g. rename or delete). Actions and parameters should be given in the opdata map.

func (*Tree) KnownBranches Uses

func (t *Tree) KnownBranches() map[string]map[string]string

KnownBranches returns a map of all known branches (active or not reachable). Caution: This map contains also the map of active branches with their fingerprints it should only be used for read operations.

func (*Tree) NotReachableBranches Uses

func (t *Tree) NotReachableBranches() map[string]map[string]string

NotReachableBranches returns a map of all known branches which couldn't be reached. The map contains the name and the definition of the branch.

func (*Tree) PingBranch Uses

func (t *Tree) PingBranch(node string, rpc string) (string, error)

PingBranch sends a ping to a remote branch and returns its fingerprint or an error.

func (*Tree) ReadFile Uses

func (t *Tree) ReadFile(spath string, p []byte, offset int64) (int, error)

ReadFile reads up to len(p) bytes into p from the given offset. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.

func (*Tree) ReadFileToBuffer Uses

func (t *Tree) ReadFileToBuffer(spath string, buf io.Writer) error

ReadFileToBuffer reads a complete file into a given buffer which implements io.Writer.

func (*Tree) Refresh Uses

func (t *Tree) Refresh()

Refresh refreshes all known branches and mappings. Only reachable branches will be mapped into the tree.

func (*Tree) Reset Uses

func (t *Tree) Reset(branches bool)

Reset either resets only all mounts or if the branches flag is specified also all known branches.

func (*Tree) SetMapping Uses

func (t *Tree) SetMapping(config string) error

SetMapping adds a given tree mapping configuration in a JSON string.

func (*Tree) Stat Uses

func (t *Tree) Stat(item string) (os.FileInfo, error)

Stat returns information about a given item. Use this function to find out if a given path is a file or directory.

func (*Tree) String Uses

func (t *Tree) String() string

String returns a string representation of this tree.

func (*Tree) Sync Uses

func (t *Tree) Sync(srcDir string, dstDir string, recursive bool,
    updFunc func(op, srcFile, dstFile string, writtenBytes, totalBytes, currentFile, totalFiles int64)) error

Sync a given destination with a given source directory. After this command has finished the dstDir will have the same files and directories as the srcDir.

func (*Tree) WriteFile Uses

func (t *Tree) WriteFile(spath string, p []byte, offset int64) (int, error)

WriteFile writes p into the given file from the given offset. It returns the number of written bytes and any error encountered.

func (*Tree) WriteFileFromBuffer Uses

func (t *Tree) WriteFileFromBuffer(spath string, buf io.Reader) error

WriteFileFromBuffer writes a complete file from a given buffer which implements io.Reader.

Directories

PathSynopsis
apiPackage api contains the REST API for RUFS.
api/v1Package v1 contains Rufs REST API Version 1.
cliRufs main entry point for the standalone server.
config
exportPackage export contains export bindings for Rufs.
nodePackage node contains the network communication code for Rufs via RPC calls.
termPackage term contains a terminal implementation which can control Rufs trees.

Package rufs imports 24 packages (graph) and is imported by 5 packages. Updated 2020-01-26. Refresh now. Tools for package owners.