catfs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: AGPL-3.0 Imports: 31 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsClosed = errors.New("File handle is closed")
)
View Source
var ErrReadOnly = errors.New("fs is read only")

Functions

This section is empty.

Types

type Change

type Change struct {
	Path    string
	Change  string
	ReferTo string
	Head    *Commit
	Next    *Commit
}

type Commit

type Commit struct {
	Hash h.Hash
	Msg  string
	Tags []string
	Date time.Time
}

Commit gives information about a single commit. TODO: Decide on naming: rev(ision), refname or tag.

type Diff

type Diff struct {
	Added   []StatInfo
	Removed []StatInfo
	Ignored []StatInfo
	Missing []StatInfo

	Moved    []DiffPair
	Merged   []DiffPair
	Conflict []DiffPair
}

type DiffPair

type DiffPair struct {
	Src StatInfo
	Dst StatInfo
}

type ErrNoSuchHash

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

ErrNoSuchHash should be returned whenever the backend is unable to find an object referenced to by this hash.

func (ErrNoSuchHash) Error

func (eh ErrNoSuchHash) Error() string

type ExplicitPin

type ExplicitPin struct {
	Path   string
	Commit string
}

type FS

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

FS (short for Filesystem) is the central API entry for everything related to paths. It exposes a POSIX-like interface where path are mapped to the actual underlying hashes and the associated metadata.

Additionally it supports version control commands like MakeCommit(), Checkout() etc. The API is file-centric, i.e. directories are created on the fly for some operations like Stage(). Empty directories can be created via Mkdir() though.

func NewFilesystem

func NewFilesystem(backend FsBackend, dbPath string, owner string, readOnly bool, fsCfg *config.Config) (*FS, error)

func (*FS) ApplyPatch

func (fs *FS) ApplyPatch(data []byte) error

ApplyPatch reads the binary patch coming from MakePatch and tries to apply it.

func (*FS) Cat

func (fs *FS) Cat(path string) (mio.Stream, error)

Cat will open a file read-only and expose it's underlying data as stream. If no such path is known or it was deleted, nil is returned as stream.

func (*FS) Checkout

func (fs *FS) Checkout(rev string, force bool) error

func (*FS) ClearExplicitPins

func (fs *FS) ClearExplicitPins(prefix, fromRef, toRef string) (int, error)

func (*FS) Close

func (fs *FS) Close() error

func (*FS) Copy

func (fs *FS) Copy(src, dst string) error

func (*FS) Export

func (fs *FS) Export(w io.Writer) error

func (*FS) FilesByContent

func (fs *FS) FilesByContent(contents []h.Hash) (map[string]StatInfo, error)

func (*FS) Head

func (fs *FS) Head() (string, error)

func (*FS) History

func (fs *FS) History(path string) ([]Change, error)

History returns all modifications of a node with one entry per commit.

func (*FS) Import

func (fs *FS) Import(r io.Reader) error

func (*FS) IsPinned

func (fs *FS) IsPinned(path string) (bool, bool, error)

IsPinned returns true for files and directories that are pinned. A directory only counts as pinned if all files and directories in it are also pinned.

func (*FS) LastPatchIndex

func (fs *FS) LastPatchIndex() (int64, error)

LastPatchIndex will return the current version of this filesystem regarding patch state.

func (*FS) List

func (fs *FS) List(root string, maxDepth int) ([]*StatInfo, error)

List returns stat info for each node below (and including) root. Nodes deeper than maxDepth will not be shown. If maxDepth is a negative number, all nodes will be shown.

func (*FS) ListExplicitPins

func (fs *FS) ListExplicitPins(prefix, fromRef, toRef string) ([]ExplicitPin, error)

func (*FS) Log

func (fs *FS) Log() ([]Commit, error)

Log returns a list of commits starting with the staging commit until the initial commit. For each commit, metadata is collected.

func (*FS) MakeCommit

func (fs *FS) MakeCommit(msg string) error

MakeCommit bundles all staged changes into one commit described by `msg`. If no changes were made since the last call to MakeCommit() ErrNoConflict is returned.

func (*FS) MakeDiff

func (fs *FS) MakeDiff(remote *FS, headRevOwn, headRevRemote string) (*Diff, error)

func (*FS) MakePatch

func (fs *FS) MakePatch(fromRev string, folders []string, remoteName string) ([]byte, error)

MakePatch creates a binary patch with all file changes starting with `fromRev`. Note that commit information is not exported, only individual file and directory changes.

The byte structured returned by this method may change at any point and may not be relied upon.

The `remoteName` is the name of the remote we're creating the patch for. It's only used for display purpose in the commit message.

func (*FS) Mkdir

func (fs *FS) Mkdir(path string, createParents bool) error

func (*FS) Move

func (fs *FS) Move(src, dst string) error

func (*FS) Open

func (fs *FS) Open(path string) (*Handle, error)

Open returns a file like object that can be used for modifying a file in memory. If you want to have seekable read-only stream, use Cat(), it has less overhead.

func (*FS) Pin

func (fs *FS) Pin(path string) error

TODO: PIN: Make pre fetch configurable.

func (*FS) Remove

func (fs *FS) Remove(path string) error

func (*FS) RemoveTag

func (fs *FS) RemoveTag(name string) error

RemoveTag removes a previously created tag.

func (*FS) Reset

func (fs *FS) Reset(path, rev string) error

func (*FS) ScheduleGCRun

func (fs *FS) ScheduleGCRun()

func (*FS) SetExplicitPin

func (fs *FS) SetExplicitPin(prefix, fromRef, toRef string) (int, error)

func (*FS) Stage

func (fs *FS) Stage(path string, r io.ReadSeeker) error

Stage reads all data from `r` and stores as content of the node at `path`. If `path` already exists, it will be updated.

func (*FS) Stat

func (fs *FS) Stat(path string) (*StatInfo, error)

func (*FS) Sync

func (fs *FS) Sync(remote *FS) error

Sync will synchronize the state of two filesystems. If one of filesystems have unstaged changes, they will be committted first. If our filesystem was changed by Sync(), a new merge commit will also be created.

func (*FS) Tag

func (fs *FS) Tag(rev, name string) error

Tag saves a human readable name for the revision pointed to by `rev`. There are three pre-defined tags available:

- HEAD: The last full commit. - CURR: The current commit (== staging commit) - INIT: the initial commit.

The tagname is case-insensitive.

func (*FS) Touch

func (fs *FS) Touch(path string) error

Touch creates an empty file at `path` if it does not exist yet. If it exists, it's mod time is being updated to the current time.

func (*FS) Truncate

func (fs *FS) Truncate(path string, size uint64) error

Truncate cuts of the output of the file at `path` to `size`. `size` should be between 0 and the size of the file, all other values will be ignored.

Note that this is not implemented as an actual IO operation. It is possible to go back to a bigger size until the actual content was changed via Stage().

func (*FS) Unpin

func (fs *FS) Unpin(path string) error

type FsBackend

type FsBackend interface {
	// Cat should find the object referenced to by `hash` and
	// make its data available as mio.Stream.
	Cat(hash h.Hash) (mio.Stream, error)

	// Add should read all data in `r` and return the hash under
	// which it can be accessed on later.
	Add(r io.Reader) (h.Hash, error)

	// Pin gives the object at `hash` a "pin".
	// (i.e. it marks the file to be stored indefinitely in local storage)
	// When pinning an explicit pin with an implicit pin, the explicit pin
	// will stay. Upgrading from implicit to explicit is possible though.
	Pin(hash h.Hash) error

	// Unpin removes a previously added pin.
	// If an object is already unpinned this is a no op.
	Unpin(hash h.Hash) error

	// IsPinned return two boolean values:
	// - If the first value is true, the file is pinned.
	IsPinned(hash h.Hash) (bool, error)
}

FsBackend is the interface that needs to be implemented by the data management layer.

type Handle

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

func (*Handle) Close

func (hdl *Handle) Close() error

func (*Handle) Flush

func (hdl *Handle) Flush() error

func (*Handle) Path

func (hdl *Handle) Path() string

func (*Handle) Read

func (hdl *Handle) Read(buf []byte) (int, error)

func (*Handle) Seek

func (hdl *Handle) Seek(offset int64, whence int) (int64, error)

func (*Handle) Truncate

func (hdl *Handle) Truncate(size uint64) error

Truncate truncates the file to a specific length.

func (*Handle) Write

func (hdl *Handle) Write(buf []byte) (int, error)

type MemFsBackend

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

MemFsBackend is a mock structure that implements FsBackend.

func NewMemFsBackend

func NewMemFsBackend() *MemFsBackend

NewMemFsBackend returns a MemFsBackend (useful for writing tests)

func (*MemFsBackend) Add

func (mb *MemFsBackend) Add(r io.Reader) (h.Hash, error)

Add implements FsBackend.Add by storing the data in memory.

func (*MemFsBackend) Cat

func (mb *MemFsBackend) Cat(hash h.Hash) (mio.Stream, error)

Cat implements FsBackend.Cat by querying memory.

func (*MemFsBackend) IsPinned

func (mb *MemFsBackend) IsPinned(hash h.Hash) (bool, error)

IsPinned implements FsBackend.IsPinned by querying a marker in memory.

func (*MemFsBackend) Pin

func (mb *MemFsBackend) Pin(hash h.Hash) error

Pin implements FsBackend.Pin by storing a marker in memory.

func (*MemFsBackend) Unpin

func (mb *MemFsBackend) Unpin(hash h.Hash) error

Unpin implements FsBackend.Unpin by removing a marker in memory.

type Pinner

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

Pinner remembers which hashes are pinned and if they are pinned explicitly. It offers also safe API to change this state easily.

func NewPinner

func NewPinner(pinDbPath string, lkr *c.Linker, bk FsBackend) (*Pinner, error)

NewPinner creates a new pin cache at `pinDbPath`, possibly erroring out. `lkr` and `bk` are used to make PinNode() and UnpinNode() work.

func (*Pinner) Close

func (pc *Pinner) Close() error

Close the pinning cache.

func (*Pinner) IsNodePinned

func (pc *Pinner) IsNodePinned(nd n.Node) (bool, bool, error)

IsNodePinned checks if all `nd` is pinned and if so, exlusively. If `nd` is a directory, it will only return true if all children are also pinned (same for second return value).

func (*Pinner) IsPinned

func (pc *Pinner) IsPinned(hash h.Hash) (isPinned bool, isExplicit bool, err error)

func (*Pinner) Pin

func (pc *Pinner) Pin(hash h.Hash, explicit bool) error

func (*Pinner) PinNode

func (pc *Pinner) PinNode(nd n.Node, explicit bool) error

PinNode tries to pin the node referenced by `nd`. The difference to calling Pin(nd.BackendHash()) is, that this method will pin directories recursively, if given.

If the file is already pinned exclusively and you want to pin it non-exclusive, this will be a no-op. In this case you have to unpin it first exclusively.

func (*Pinner) Unpin

func (pc *Pinner) Unpin(hash h.Hash, explicit bool) error

func (*Pinner) UnpinNode

func (pc *Pinner) UnpinNode(nd n.Node, explicit bool) error

UnpinNode is the exact opposite of PinNode.

type StatInfo

type StatInfo struct {
	Path        string
	TreeHash    h.Hash
	User        string
	Size        uint64
	Inode       uint64
	IsDir       bool
	Depth       int
	ModTime     time.Time
	IsPinned    bool
	IsExplicit  bool
	ContentHash h.Hash
	BackendHash h.Hash
}

StatInfo describes the metadata of a single node. The concept is comparable to the POSIX stat() call.

Directories

Path Synopsis
mio
package mio (short for memory input/output) implements the layered io stack of brig.
package mio (short for memory input/output) implements the layered io stack of brig.
encrypt
Package encrypt implements the encryption layer of brig.
Package encrypt implements the encryption layer of brig.
Package nodes implements all nodes and defines basic operations on it.
Package nodes implements all nodes and defines basic operations on it.
vcs

Jump to

Keyboard shortcuts

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