ws

package
v0.0.0-...-0f24718 Latest Latest
Warning

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

Go to latest
Published: May 13, 2016 License: BSD-2-Clause Imports: 12 Imported by: 9

Documentation

Overview

Package ws implements a workspace for file resources.

Index

Constants

View Source
const (
	FlagDir uint64 = 1 << iota
	FlagLogical
	FlagMount
	FlagIgnore
)

Variables

View Source
var Skip = fmt.Errorf("skip")

Skip is returned by walk visitors to prevent visiting children of the resource in context.

Functions

func MountAll

func MountAll(w *Ws, paths []string) []error

MountAll mounts all paths into workspace w. Paths are mounted in parallel if possible.

Types

type Config

type Config struct {
	// CapHint hints the expected peak resource capacity.
	CapHint uint
	// Watcher returns a new watcher given workspace control.
	// Mounting a path results in a snapshot if no Watcher is configured.
	Watcher func(Controller) (Watcher, error)
	// Handler handles events if set.
	Handler Handler
	// Filter filters resources if set.
	Filter Filter
}

Config contains the configuration used to create new workspaces.

type Controller

type Controller interface {
	Control(op Op, id Id, name string) error
}

Controller provides an interface for the watcher to modify the workspace.

type Dir

type Dir struct {
	Path     string
	Children []*Res
}

Dir holds the full path and child resources for a directory resource.

type Filter

type Filter interface {
	Filter(*Res) bool
}

Filter checks new resources and returns true if the resources should be flagged as ignored. Resources with FlagIgnore remain in the workspace. Ignored directories are not read.

type Handler

type Handler interface {
	Handle(Op, *Res)
}

Handler handles resource operation events.

type Id

type Id uint32

Id identifies a workspace resource uniquely. Having a fnv32 hash collision is considered a user error.

func NewId

func NewId(path string) Id

Creates a workspace id for path. Path must be absolute and clean (sans trailing slash).

func (Id) MarshalJSON

func (id Id) MarshalJSON() ([]byte, error)

func (*Id) UnmarshalJSON

func (id *Id) UnmarshalJSON(data []byte) error

type Op

type Op uint

Op describes workspace and filesystem operations or events

const (
	Add Op = 1 << iota
	Change
	Remove

	Create
	Modify
	Delete

	WsMask Op = 0x0F
	FsMask Op = 0xF0
)

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue implements a locked resource queue.

func (*Queue) Add

func (q *Queue) Add(r *Res)

Add enqueues the resource. Resources already enqueued move to the end.

func (*Queue) Delete

func (q *Queue) Delete(r *Res)

Delete dequeues the resource.

func (*Queue) Work

func (q *Queue) Work() []*Res

Work returns enqueued resources.

type Res

type Res struct {
	sync.Mutex
	Id     Id
	Name   string
	Flag   uint64
	Parent *Res
	*Dir
}

Res describes a workspace resource.

func (*Res) Path

func (r *Res) Path() string

Path returns the full resource path.

type Throttle

type Throttle struct {
	sync.Mutex

	Tickers chan *time.Ticker
	// contains filtered or unexported fields
}

Throttle manages a ticker and swaps two queue when worked. New tickers are sent to the Tickers channel and run as long as work is available.

func NewThrottle

func NewThrottle(delay time.Duration) *Throttle

func (*Throttle) Add

func (q *Throttle) Add(r *Res)

Add enqueues the resource and starts a ticker if necessary.

func (*Throttle) Delete

func (q *Throttle) Delete(r *Res)

Delete dequeues the resource.

func (*Throttle) Work

func (q *Throttle) Work() []*Res

Work returns enqueued resources and stops the ticker if necessary.

type Watcher

type Watcher interface {
	Watch(r *Res) error
	Close() error
}

Watcher provides and interface for workspace watchers.

func NewInotify

func NewInotify(ctrler Controller) (Watcher, error)

type Ws

type Ws struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Ws implements a workspace that manages all mounted resources.

func New

func New(c Config) *Ws

New creates a workspace with configuration c.

func (*Ws) Close

func (w *Ws) Close()

Close closes the workspace. The workspace and all its resources are invalid afterwards.

func (*Ws) Mount

func (w *Ws) Mount(path string) (*Res, error)

Mount adds the directory tree at path to the workspace.

func (*Ws) Res

func (w *Ws) Res(id Id) *Res

Res returns the resource with id or nil.

func (*Ws) Walk

func (w *Ws) Walk(list []*Res, visit func(r *Res) error) error

Walk calls visit for all resources in list and all their descendants. If the visit returns Skip for a resource its children are not visited.

Jump to

Keyboard shortcuts

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