model

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Default uint8 = iota
	Started
	Finished
	Aborted
	Paused
)

Variables

View Source
var (
	ErrCancelled        = errors.New("cancelled copy")
	ErrMkdir            = errors.New("mkdir error")
	ErrDstFile          = errors.New("dst file")
	ErrDstAlreadyExists = errors.New("dst file already exists")
	ErrSrcFile          = errors.New("src file")
	ErrSkipFile         = errors.New("skip file")
)

Functions

This section is empty.

Types

type Collection

type Collection []FileInfo

func DirToCollection

func DirToCollection(fs afero.Fs, base string) (Collection, error)

DirToCollection gets all files within a directory and adds them to a collection.

func FsToCollection

func FsToCollection(localfs afero.Fs) (Collection, error)

FsToCollection takes in an afero file system and turns it into a collection of files. The collection is always recursive.

type Controller

type Controller interface {
	// Error is a function that tells the client that their request
	// encountered an error.
	Error(err ControllerError)
	// Value is a function that tells the client that their request
	// was successful with an extra value.
	Value(val interface{}) error
}

type ControllerError

type ControllerError struct {
	ID     string `json:"id"`
	Reason string `json:"reason"`
}

type DummyController

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

func (*DummyController) Error

func (d *DummyController) Error(err ControllerError)

func (*DummyController) GetError

func (d *DummyController) GetError() *ControllerError

func (*DummyController) Read

func (d *DummyController) Read(v interface{}) error

func (*DummyController) Value

func (d *DummyController) Value(val interface{}) error

type FileInfo

type FileInfo struct {
	Fs      afero.Fs
	File    os.FileInfo
	Path    string
	AbsPath string
}

func (FileInfo) MarshalJSON

func (f FileInfo) MarshalJSON() ([]byte, error)

type Fs

type Fs interface {
	afero.Fs
	IsMounted() error
	Mount() error
	Unmount() error
}

type JSONError

type JSONError struct {
	Err error
}

func (*JSONError) MarshalJSON

func (j *JSONError) MarshalJSON() ([]byte, error)

type Operation

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

Operation is an object that contains a file transfer from multiple sources to one destination. An operation can be paused, resumed, or cancelled(Exit).

Operations typically endure errors but through Operation.Error these errors can be dynamically handled by an outsider package so that Operation is extensible via other packages.

func NewOperation

func NewOperation(src Collection, dst afero.Fs) (*Operation, error)

NewOperation returns an operation object.

func (*Operation) Destination

func (o *Operation) Destination() afero.Fs

Destination returns the destination file system. Please note that destinations should not be changed, instead create a new operation.

func (*Operation) Error

func (o *Operation) Error() OperationError

Error returns the error if there is any, or hangs if there isn't an error.

func (*Operation) Exit

func (o *Operation) Exit() error

Exit exits out of the operation. Exit can happen while writing to a file, or while preparing to write to a file. If the file is being written to and Exit is called, then the file gets deleted afterwards.

Exit makes an operation obsolete.

func (*Operation) Index

func (o *Operation) Index() int

Index returns the index of the current file

func (*Operation) Pause

func (o *Operation) Pause() error

Pause pauses the operation temporarily.

func (*Operation) RateLimit

func (o *Operation) RateLimit() float64

func (*Operation) Resume

func (o *Operation) Resume() error

Resume resumes the operation.

func (*Operation) SetIndex

func (o *Operation) SetIndex(n int)

SetIndex sets the index for the collection. Can be used to skip a file whilst it is being written to.

func (*Operation) SetLogger

func (o *Operation) SetLogger(l distillog.Logger)

SetLogger sets the logger for the Operation

func (*Operation) SetProgress

func (o *Operation) SetProgress(v ProgressSetter)

SetProgress sets the progress setter for the files.

func (*Operation) SetRateLimit

func (o *Operation) SetRateLimit(val float64)

SetRateLimit sets a rate limit for how fast can a reader be read.

func (*Operation) SetSources

func (o *Operation) SetSources(c Collection)

SetSources sets the sources for the operation.

func (*Operation) Size

func (o *Operation) Size() int64

Size returns the src size of the operation. Do note that this function is rather expensive as it contains tons of syscalls. Prefer to send a cached value and calling the function only when the sources have changed.

func (*Operation) Sources

func (o *Operation) Sources() Collection

Sources returns the list of files that are to be copied ot the destination.

func (*Operation) Start

func (o *Operation) Start() error

Start starts the operation

func (*Operation) Status

func (o *Operation) Status() uint8

Status returns the operation's status

type OperationError

type OperationError struct {
	Index int
	Src   FileInfo
	Dst   afero.Fs
	Error error
}

OperationError is an error that can occur in the middle of an operation.

type OperationFile

type OperationFile struct {
	Name    string `json:"name"`
	Path    string `json:"path"`
	Size    int64
	ModTime time.Time
	IsDir   bool
}

OperationFile is a marshallable object that is used to communicate with Controller.

type OperationProgress

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

type OsFileInfo

type OsFileInfo struct {
	os.FileInfo
	Path         string
	AbsolutePath string
	FakeMode     *fs.FileMode
}

OsFileInfo is a wrapper around os.FileInfo that allows it to be marshalled to json.

func NewOsFileInfo

func NewOsFileInfo(o os.FileInfo, path, abs string) OsFileInfo

func (OsFileInfo) Map

func (o OsFileInfo) Map() map[string]interface{}

func (OsFileInfo) MarshalJSON

func (o OsFileInfo) MarshalJSON() ([]byte, error)

type ProgressSetter

type ProgressSetter interface {
	// Set is a function that provides real-time updates (writes) for clients.
	// Set must be safe for concurrent use.
	Set(index int, written int64)
}

ProgressSetter is an interface that allows for progress setting for files. Whenever a file gets written to in *Operation, ProgressSetter's Set function is called.

In conjuction with index and src, ProgressSetter can provide real time progress of the file transfers.

type PublicOperation

type PublicOperation struct {
	*Operation
	Destination string `json:"dst"`
}

func (PublicOperation) Map

func (po PublicOperation) Map() map[string]interface{}

func (PublicOperation) MarshalJSON

func (po PublicOperation) MarshalJSON() ([]byte, error)

type Server

type Server interface {
	Start() error
	IsRunning() bool
	Stop() error
}

Jump to

Keyboard shortcuts

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