filetree

package
v0.0.0-...-b178995 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FTBinary   = "binary"
	FTText     = "text"
	FTVideo    = "video"
	FTImage    = "image"
	FTArchive  = "archive"
	FTDocument = "document"
)

Variables

View Source
var (
	// FIXME(tsileo): add a way to set a custom fmt key life for Blobs CLI as we don't care about the FS?
	FSKeyFmt = "_filetree:fs:%s"

	MaxUploadSize int64 = 512 << 20 // 512MB
)

Functions

This section is empty.

Types

type BlobStore

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

func NewBlobStoreCompat

func NewBlobStoreCompat(bs store.BlobStore, ctx context.Context) *BlobStore

BlobStore is the interface to be compatible with both the server and the BlobStore client

func (*BlobStore) Get

func (bs *BlobStore) Get(hash string) ([]byte, error)

func (*BlobStore) Put

func (bs *BlobStore) Put(ctx context.Context, hash string, data []byte) error

func (*BlobStore) Stat

func (bs *BlobStore) Stat(ctx context.Context, hash string) (bool, error)

type FS

type FS struct {
	Name     string `json:"-"`
	Ref      string `json:"ref"`
	AsOf     int64  `json:"-"`
	Revision int64  `json:"-"`
	// contains filtered or unexported fields
}

func NewFS

func NewFS(ref string, ft *FileTree) *FS

func (*FS) Mkdir

func (fs *FS) Mkdir(ctx context.Context, prefixFmt, path, name string) (*Node, error)

func (*FS) Path

func (fs *FS) Path(ctx context.Context, path string, depth int, create bool, mtime int64) (*Node, *rnode.RawNode, bool, error)

Path returns the `Node` at the given path, create it if requested

func (*FS) Root

func (fs *FS) Root(ctx context.Context, create bool, mtime int64) (*Node, error)

Root fetch the FS root, and creates a new one if `create` is set to true (but it won't be savec automatically in the BlobStore

type FSInfo

type FSInfo struct {
	Name string
	Ref  string
}

type FSUpdateEvent

type FSUpdateEvent struct {
	Name      string `json:"fs_name"`
	Path      string `json:"fs_path"`
	Ref       string `json:"node_ref"`
	Type      string `json:"node_type"`
	Time      int64  `json:"event_time"`
	Hostname  string `json:"event_hostname"`
	SessionID string `json:"session_id"`
}

FSUpdateEvent represents an even fired on FS update to the Oplog

func (*FSUpdateEvent) JSON

func (e *FSUpdateEvent) JSON() string

type FileTree

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

func New

func New(logger log.Logger, conf *config.Config, authFunc func(*http.Request) bool, kvStore store.KvStore, blobStore store.BlobStore, chub *hub.Hub) (*FileTree, error)

New initializes the `DocStoreExt`

func (*FileTree) AddChild

func (ft *FileTree) AddChild(ctx context.Context, snap *Snapshot, n *Node, newChild *rnode.RawNode, prefixFmt string, mtime int64) (*Node, int64, error)

Update the given node with the given meta, the updated/new node is assumed to be already saved

func (*FileTree) BFS

func (ft *FileTree) BFS(ctx context.Context, root *Node, fn func(*Node) (bool, error)) (*Node, error)

BFS performs a Breadth-first search

func (*FileTree) BruteforcePath

func (ft *FileTree) BruteforcePath(ctx context.Context, root, target string) ([]*NodeInfo, error)

BruteforcePath builds the path from a children hash/ref

func (*FileTree) Close

func (ft *FileTree) Close() error

Close closes all the open DB files.

func (*FileTree) CreateFS

func (ft *FileTree) CreateFS(ctx context.Context, fsName, prefixFmt string) (*Node, error)

func (*FileTree) DFS

func (ft *FileTree) DFS(ctx context.Context, root *Node, fn func(*Node) (bool, error)) (*Node, error)

DFS performs a (recursive) Depth-first search

func (*FileTree) Delete

func (ft *FileTree) Delete(ctx context.Context, snap *Snapshot, n *Node, prefixFmt string, mtime int64) (*Node, int64, error)

Delete removes the given node from its parent children

func (*FileTree) FS

func (ft *FileTree) FS(ctx context.Context, name, prefixFmt string, newState bool, asOf int64) (*FS, error)

FS fetch the FileSystem by name, returns an empty one if not found

func (ft *FileTree) GetSemiPrivateLink(n *Node) (string, string, error)
func (ft *FileTree) GetTgzLink(n *Node) (string, error)
func (ft *FileTree) GetWebmLink(n *Node) (string, string, error)

func (*FileTree) IterFS

func (ft *FileTree) IterFS(ctx context.Context, start string) ([]*FSInfo, error)

func (*FileTree) IterTree

func (ft *FileTree) IterTree(ctx context.Context, root *Node, fn func(*Node, string) error) error

IterFS iterates the whole FS tree and executes `fn` on each node

func (*FileTree) LuaFSVersions

func (ft *FileTree) LuaFSVersions(name string) ([]*Snapshot, error)

func (*FileTree) Node

func (ft *FileTree) Node(ctx context.Context, hash string) (*Node, error)

func (*FileTree) NodeWithChildren

func (ft *FileTree) NodeWithChildren(ctx context.Context, hash string) (*Node, error)

func (*FileTree) Register

func (ft *FileTree) Register(r *mux.Router, root *mux.Router, basicAuth func(http.Handler) http.Handler)

RegisterRoute registers all the HTTP handlers for the extension

func (*FileTree) ShareTTL

func (ft *FileTree) ShareTTL() time.Duration

func (*FileTree) SharingCred

func (ft *FileTree) SharingCred() *bewit.Cred

func (*FileTree) TreeBlobs

func (ft *FileTree) TreeBlobs(ctx context.Context, node *Node) ([]string, error)

func (*FileTree) Update

func (ft *FileTree) Update(ctx context.Context, snap *Snapshot, n *Node, m *rnode.RawNode, prefixFmt string, first bool) (*Node, int64, error)

Update the given node with the given meta, the updated/new node is assumed to be already saved

type GraphSearchFunc

type GraphSearchFunc = func(context.Context, *Node, func(*Node) (bool, error)) (*Node, error)

GraphSearchFunc is the interface type for the different graph transversal algorithms (BFS,DFS)

type Info

type Info struct {
	Image *imginfo.Image `json:"image,omitempty" msgpack:"image,omitempty"`
	Video *vidinfo.Video `json:"video,omitempty" msgpack:"video,omitempty"`
}

type Node

type Node struct {
	Name          string  `json:"name" msgpack:"n"`
	Type          string  `json:"type" msgpack:"t"`
	FileType      string  `json:"file_type,omitempty" msgpack:"ft,omitempty"`
	Size          int     `json:"size,omitempty" msgpack:"s,omitempty"`
	Mode          int     `json:"mode,omitempty" msgpack:"mo,omitempty"`
	ModTime       string  `json:"mtime" msgpack:"mt"`
	ChangeTime    string  `json:"ctime" msgpack:"ct"`
	ContentHash   string  `json:"content_hash,omitempty" msgpack:"ch,omitempty"`
	Hash          string  `json:"ref" msgpack:"r"`
	Children      []*Node `json:"children,omitempty" msgpack:"c,omitempty"`
	ChildrenCount int     `json:"children_count,omitempty" msgpack:"cc,omitempty"`

	// FIXME(ts): rename to Metadata
	Data map[string]interface{} `json:"metadata,omitempty" msgpack:"md,omitempty"`
	Info *Info                  `json:"info,omitempty" msgpack:"i,omitempty"`

	Meta *rnode.RawNode `json:"-" msgpack:"-"`

	URL  string            `json:"url,omitempty" msgpack:"u,omitempty"`
	URLs map[string]string `json:"urls,omitempty" msgpack:"us,omitempty"`
	// contains filtered or unexported fields
}

Node holds the data about the file node (either file/dir), analog to a Meta

func (*Node) Close

func (n *Node) Close() error

type NodeInfo

type NodeInfo struct {
	Name, Ref string
}

NodeInfo represents a node for the path/breadcrumbs

type Snapshot

type Snapshot struct {
	Ref       string `msgpack:"-" json:"ref"`
	CreatedAt int64  `msgpack:"-" json:"created_at"`

	Hostname  string `msgpack:"h" json:"hostname,omitempty"`
	Message   string `msgpack:"m,omitempty" json:"message,omitempty"`
	UserAgent string `msgpack:"ua,omitempty" json:"user_agent,omitempty"`
}

TODO(tsileo): a way to create a snapshot without modifying anything (and forcing the datactx before)

Directories

Path Synopsis
filetreeutil
node
Package node implement the node specification for the filetree extension.
Package node implement the node specification for the filetree extension.

Jump to

Keyboard shortcuts

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