storagesystem

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0, MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackendMap = make(map[string]Backend)
View Source
var Backends []Backend
View Source
var ErrBackendNotSupported = errors.New("This backend is not supported")
View Source
var ErrGetUsageNotSupported = errors.New("The backend does not support getting usage quota")
View Source
var ErrMoveNotSupported = errors.New("The backend does not support moving files")
View Source
var ErrStorageNotAvailable = errors.New("storage not available")

Functions

func GetHash

func GetHash(ctx context.Context, object fs.ObjectInfo) (string, error)

func IsSameEntry

func IsSameEntry(ctx context.Context, file model.File, object fs.ObjectInfo) (bool, string)

IsSameEntry checks if a given model.File and a given fs.Object represent the same entry, based on their size, hash, and last modification time.

Parameters:

  • ctx: Context that allows for asynchronous task cancellation.
  • file: A model.File instance representing a file in the model.
  • object: An fs.Object instance representing a file or object in the filesystem.

Returns:

  • bool: A boolean indicating whether the given model.File and fs.Object are considered the same entry.
  • string: A string providing details in case of a mismatch.

The function performs the following checks:

  1. Compares the sizes of 'file' and 'object'. If there is a mismatch, it returns false along with a formatted string that shows the mismatched sizes.
  2. Retrieves the last modified time of 'object'.
  3. Identifies a supported hash type for the storage backend of 'object' and computes its hash value.
  4. The hash computation is skipped if the storage backend is a local file system or does not support any hash types.
  5. If both 'file' and 'object' have non-empty hash values and these values do not match, it returns false along with a formatted string that shows the mismatched hash values.
  6. Compares the last modified times of 'file' and 'object' at the nanosecond precision. If there is a mismatch, it returns false along with a formatted string that shows the mismatched times.
  7. If all the checks pass (sizes, hashes, and last modified times match), the function returns true, indicating that 'file' and 'object' are considered to be the same entry.

Note: - In certain cases (e.g., failures during fetch), the last modified time might not be reliable. - For local file systems, hash computation is skipped to avoid inefficient operations.

Types

type Backend

type Backend struct {
	// Name of this fs
	Name string
	// Description of this fs - defaults to Name
	Description string
	// Prefix for command line flags for this fs - defaults to Name if not set
	Prefix string
	// Different Config by Provider
	ProviderOptions []ProviderOptions
}

type EmptyReadCloser

type EmptyReadCloser struct{}

EmptyReadCloser is a ReadCloser that always returns EOF.

func (*EmptyReadCloser) Close

func (e *EmptyReadCloser) Close() error

func (*EmptyReadCloser) Read

func (e *EmptyReadCloser) Read(p []byte) (n int, err error)

type Entry

type Entry struct {
	Error error
	Info  fs.Object
}

Entry is a struct that represents a single file during a data source scan.

type Handler

type Handler interface {
	Reader
	Writer
	Lister
	fs.Abouter
}

Handler is an interface for all relevant operations allowed by an RClone backend.

type Lister

type Lister interface {
	Name
	// List lists the files at the given path.
	List(ctx context.Context, path string) ([]fs.DirEntry, error)

	// Scan scans the data source starting at the given path and returns a channel of entries.
	// The `last` parameter is used to resume scanning from the last entry returned by a previous scan. It is exclusive.
	// The returned entries must be sorted by path in ascending order.
	Scan(ctx context.Context, path string, last string) <-chan Entry

	// Check checks the size and last modified time of the file at the given path.
	Check(ctx context.Context, path string) (fs.DirEntry, error)
}

type Name

type Name interface {
	Name() string
}

type Option

type Option fs.Option

func (*Option) ToCLIFlag

func (option *Option) ToCLIFlag(prefix string, useBuiltIn bool, category string) cli.Flag

type ProviderOptions

type ProviderOptions struct {
	Provider            string
	ProviderDescription string
	Options             []Option
}

func (ProviderOptions) ToCLICommand

func (p ProviderOptions) ToCLICommand(short string, long string, description string) *cli.Command

type RCloneHandler

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

func NewRCloneHandler

func NewRCloneHandler(ctx context.Context, s model.Storage) (*RCloneHandler, error)

func (RCloneHandler) About

func (h RCloneHandler) About(ctx context.Context) (*fs.Usage, error)

func (RCloneHandler) Check

func (h RCloneHandler) Check(ctx context.Context, path string) (fs.DirEntry, error)

func (RCloneHandler) List

func (h RCloneHandler) List(ctx context.Context, path string) ([]fs.DirEntry, error)

func (RCloneHandler) Move

func (h RCloneHandler) Move(ctx context.Context, from fs.Object, to string) (fs.Object, error)

func (RCloneHandler) Name

func (h RCloneHandler) Name() string

func (RCloneHandler) Read

func (h RCloneHandler) Read(ctx context.Context, path string, offset int64, length int64) (io.ReadCloser, fs.Object, error)

func (RCloneHandler) Remove

func (h RCloneHandler) Remove(ctx context.Context, obj fs.Object) error

func (RCloneHandler) Scan

func (h RCloneHandler) Scan(ctx context.Context, path string, last string) <-chan Entry

func (RCloneHandler) Write

func (h RCloneHandler) Write(ctx context.Context, path string, in io.Reader) (fs.Object, error)

type Reader

type Reader interface {
	Name
	// Read reads data from the source storage file starting at the given path and offset, and returns a ReadCloser.
	// The `length` parameter specifies the number of bytes to read.
	// This method is most likely used for retrieving a single block of data.
	Read(ctx context.Context, path string, offset int64, length int64) (io.ReadCloser, fs.Object, error)
}

type Writer

type Writer interface {
	Name
	// Write writes data to the output storage file.
	Write(ctx context.Context, path string, in io.Reader) (fs.Object, error)
	// Move moves the given object to the given path.
	Move(ctx context.Context, from fs.Object, to string) (fs.Object, error)
	// Remove removes the given object.
	Remove(ctx context.Context, obj fs.Object) error
}

func GetRandomOutputWriter

func GetRandomOutputWriter(ctx context.Context, storages []model.Storage) (*uint32, Writer, error)

Jump to

Keyboard shortcuts

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