es_filesystem

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileSystemTypeMock = "mock"
)

Variables

This section is empty.

Functions

func CompareEntry

func CompareEntry(a, b Entry) bool

Types

type Connector

type Connector interface {
	// Copy source to target system. Target path must include file name.
	// Connector callbacks onSuccess or onFailure to tell an result.
	// Copy operation may block to wait I/O.
	Copy(source Entry,
		target Path,
		onSuccess func(pair CopyPair, copied Entry),
		onFailure func(pair CopyPair, err FileSystemError))

	// Start up the connector
	Startup(qd eq_queue.Definition) (err FileSystemError)

	// Clean up connector
	Shutdown() (err FileSystemError)
}

type CopyPair

type CopyPair struct {
	Source Entry
	Target Path
}

func NewCopyPair

func NewCopyPair(source Entry, target Path) CopyPair

type Entry

type Entry interface {
	// Name of the entry.
	Name() string

	// Path of the entry.
	Path() Path

	// Size of the entry.
	Size() int64

	// Modification time.
	ModTime() time.Time

	// Content hash.
	ContentHash() (string, FileSystemError)

	// True when the entry is a file.
	IsFile() bool

	// True when the entry is a folder.
	IsFolder() bool

	// Convert as serializable data
	AsData() EntryData
}

func NewMockFileEntry

func NewMockFileEntry(path string, size int64, modTime time.Time, mockHash string) Entry

func NewMockFolderEntry

func NewMockFolderEntry(path string) Entry

type EntryData

type EntryData struct {
	FileSystemType string                 `json:"file_system_type"`
	EntryName      string                 `json:"name"`
	EntryPath      string                 `json:"path"`
	EntrySize      int64                  `json:"size"`
	EntryModTime   time.Time              `json:"mod_time"`
	EntryIsFile    bool                   `json:"is_file"`
	EntryIsFolder  bool                   `json:"is_folder"`
	Attributes     map[string]interface{} `json:"attributes,omitempty"`
}

func (EntryData) AsData

func (z EntryData) AsData() EntryData

func (EntryData) IsFile

func (z EntryData) IsFile() bool

func (EntryData) IsFolder

func (z EntryData) IsFolder() bool

func (EntryData) ModTime

func (z EntryData) ModTime() time.Time

func (EntryData) Name

func (z EntryData) Name() string

func (EntryData) Size

func (z EntryData) Size() int64

type FileSystem

type FileSystem interface {
	// List entries of the path.
	List(path Path) (entries []Entry, err FileSystemError)

	// Retrieve entry of the path.
	Info(path Path) (entry Entry, err FileSystemError)

	// Delete path.
	Delete(path Path) (err FileSystemError)

	// Create folder. Returns created entry on success, otherwise returns nil for entry.
	CreateFolder(path Path) (entry Entry, err FileSystemError)

	// Deserialize entry from entry data.
	// Returns err if the format is not valid for this file system.
	Entry(data EntryData) (entry Entry, err FileSystemError)

	// Deserialize path from path data.
	Path(data PathData) (path Path, err FileSystemError)

	// Deserialize shard from shard data.
	Shard(data ShardData) (shard Shard, err FileSystemError)

	// Type of file system
	FileSystemType() string

	// Operation complexity parameter in this file system
	OperationalComplexity(entries []Entry) (complexity int64)
}

Abstract file system interface.

type FileSystemError

type FileSystemError interface {
	error

	// True if a path is not found.
	IsPathNotFound() bool

	// True if an operation detect conflict of the path.
	IsConflict() bool

	// True if the user doesn't have permissions to write to the target.
	IsNoPermission() bool

	// True if the file system doesn't have enough available space to write more data.
	IsInsufficientSpace() bool

	// True if the file system doesn't allow name of the entry.
	IsDisallowedName() bool

	// True if the entry data is not valid for this file system.
	IsInvalidEntryDataFormat() bool

	// True if the error is for testing
	IsMockError() bool
}

func NewLowLevelError

func NewLowLevelError(ge error) FileSystemError

type MockEntry

type MockEntry struct {
	EntryData
	MockHash string `json:"content_hash"`
}

func (MockEntry) ContentHash

func (z MockEntry) ContentHash() (string, FileSystemError)

func (MockEntry) Path

func (z MockEntry) Path() Path

type MockPath

type MockPath struct {
	PathData
}

func (MockPath) Ancestor

func (z MockPath) Ancestor() Path

func (MockPath) Base

func (z MockPath) Base() string

func (MockPath) Descendant

func (z MockPath) Descendant(pathFragment ...string) Path

func (MockPath) IsRoot

func (z MockPath) IsRoot() bool

type Path

type Path interface {
	// Base name of the path entry.
	Base() string

	// Cleaned absolute path in the file system.
	Path() string

	// Shard of the path.
	Shard() Shard

	// Ancestor path. Returns root path if this instance is root.
	Ancestor() Path

	// Returns descendant path with pathFragment.
	Descendant(pathFragment ...string) Path

	// True if the path indicates root path of the namespace.
	IsRoot() bool

	// Serialize
	AsData() PathData
}

func NewMockPath

func NewMockPath(path string) Path

type PathData

type PathData struct {
	FileSystemType string                 `json:"file_system_type"`
	EntryPath      string                 `json:"entry_path"`
	EntryShard     ShardData              `json:"entry_shard"`
	Attributes     map[string]interface{} `json:"attributes"`
}

func (PathData) AsData

func (z PathData) AsData() PathData

func (PathData) Path

func (z PathData) Path() string

func (PathData) Shard

func (z PathData) Shard() Shard

type Shard

type Shard interface {
	// string representation of Shard ID.
	// Drive letter, or server name for windows file system (e.g. C:, \\SERVER\).
	// Or namespace ID (shared_folder_id/team_folder_id) of Dropbox file system.
	Id() string

	// Serialize
	AsData() ShardData
}

Shard is for load balancing factor.

type ShardData

type ShardData struct {
	FileSystemType string                 `json:"file_system_type"`
	ShardId        string                 `json:"shard_id"`
	Attributes     map[string]interface{} `json:"attributes"`
}

Serializable form of Shard

func (ShardData) AsData

func (z ShardData) AsData() ShardData

func (ShardData) Id

func (z ShardData) Id() string

Jump to

Keyboard shortcuts

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