treedb

package module
v0.0.0-...-8b3ab32 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2017 License: Apache-2.0 Imports: 10 Imported by: 3

README

treedb

A simple abstraction on top of BoltDB to store hierarchical (tree structured) data

Documentation

Index

Constants

View Source
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

View Source
var (
	//ErrNotDirectory is returned when a directory was expected
	ErrNotDirectory = errors.New("not a directory")
	//ErrNotEmptyDirectory tells us the directory was not empty
	ErrNotEmptyDirectory = errors.New("directory is not empty")
)
View Source
var (
	// ErrInvalidPath is returned when no valid filename can be created from path components
	ErrInvalidPath = errors.New("invalid path components")
)
View Source
var (
	//Root is a path with zero components: len(Root) = 0
	Root = P{}
)

Functions

This section is empty.

Types

type File

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

File provides an handler for IO, it is not safe for concurrent writing. It works with an internal cursor that can be written to and read from Dakony: - ReadFile(ctx context.Context, fi *FileInfo, bs []byte, offset int64) (int, error) - WriteFile(ctx context.Context, fi *FileInfo, bs []byte, offset int64) (int, error) - FlushFileBuffers(ctx context.Context, fi *FileInfo) error FUSE: - fs.HandleReader:

type ReadRequest struct {
    Header    `json:"-"`
    Dir       bool // is this Readdir?
    Handle    HandleID
    Offset    int64
    Size      int
    Flags     ReadFlags
    LockOwner uint64
    FileFlags OpenFlags
}

- fs.HandleWriter - fs.HandleFlusher

func NewFile

func NewFile(fs *FileSystem, p P) *File

NewFile sets up a file on filesystem 'fs' at path 'p'

func (*File) Readdir

func (f *File) Readdir(n int) (fis []os.FileInfo, err error)

Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.

If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.

func (*File) Readdirnames

func (f *File) Readdirnames(n int) (names []string, err error)

Readdirnames reads and returns a slice of names from the directory f.

If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error.

type FileSystem

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

FileSystem holds file information

func NewFileSystem

func NewFileSystem(id string, db *bolt.DB) (fs *FileSystem, err error)

NewFileSystem sets up a new file system in a bolt database with an unique id that allows multiple filesystems per database

func (*FileSystem) Mkdir

func (fs *FileSystem) Mkdir(p P, perm os.FileMode) (err error)

Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.

func (*FileSystem) Open

func (fs *FileSystem) Open(p P) (*File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func (*FileSystem) OpenFile

func (fs *FileSystem) OpenFile(p P, flag int, perm os.FileMode) (f *File, err error)

OpenFile is the generalized open call. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError. Behaviour can be customized with the following flags:

O_RDONLY int = syscall.O_RDONLY // open the file read-only.
O_WRONLY int = syscall.O_WRONLY // open the file write-only.
O_RDWR   int = syscall.O_RDWR   // open the file read-write.
O_APPEND int = syscall.O_APPEND // append data to the file when writing.
O_SYNC   int = syscall.O_SYNC   // open for synchronous I/O.
O_TRUNC  int = syscall.O_TRUNC  // if possible, truncate file when opened.
O_CREATE int = syscall.O_CREATE  // create a new file if none exists.
O_EXCL   int = syscall.O_EXCL   // used with O_CREATE, file must not exist

func (*FileSystem) Remove

func (fs *FileSystem) Remove(p P) (err error)

Remove removes the named file or directory. If there is an error, it will be of type *PathError.

func (*FileSystem) RemoveAll

func (fs *FileSystem) RemoveAll(p P) (err error)

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).

func (*FileSystem) Stat

func (fs *FileSystem) Stat(p P) (fi os.FileInfo, err error)

Stat returns a FileInfo describing the named file

type K

type K [sha256.Size]byte

K is the content hash of a file chunk

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 PathFromKey

func PathFromKey(k []byte) P

PathFromKey turns a database key into its Path representation

func (P) Base

func (p P) Base() string

Base returns the base component of a path

func (P) Err

func (p P) Err(op string, err error) *os.PathError

Err allows easy creation of PathErrors

func (P) Key

func (p P) Key() []byte

Key returns a byte slice used for database retrieval and storage

func (P) Parent

func (p P) Parent() P

Parent returns a path that refers to a parent, if the current path is the root the root is still returned

func (P) String

func (p P) String() string

String implements stringer for the Path type that returns something more human friendly that shows familiar forward slashes

func (P) Validate

func (p P) Validate() error

Validate is used to check if a given Path is valid, it returns an ErrInvalidPath if the path is invalid nil otherwise

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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