Documentation ¶
Index ¶
- Variables
- func GetHash(ctx context.Context, object fs.ObjectInfo) (string, error)
- func IsSameEntry(ctx context.Context, file model.File, object fs.ObjectInfo) (bool, string)
- func Open(h Handler, ctx context.Context, path string) (io.ReadSeekCloser, fs.DirEntry, error)
- type Backend
- type EmptyReadCloser
- type Entry
- type Handler
- type Lister
- type Name
- type Option
- type ProviderOptions
- type RCloneHandler
- func (h RCloneHandler) About(ctx context.Context) (*fs.Usage, error)
- func (h RCloneHandler) Check(ctx context.Context, path string) (fs.DirEntry, error)
- func (h RCloneHandler) List(ctx context.Context, path string) ([]fs.DirEntry, error)
- func (h RCloneHandler) Move(ctx context.Context, from fs.Object, to string) (fs.Object, error)
- func (h RCloneHandler) Name() string
- func (h RCloneHandler) Read(ctx context.Context, path string, offset int64, length int64) (io.ReadCloser, fs.Object, error)
- func (h RCloneHandler) Remove(ctx context.Context, obj fs.Object) error
- func (h RCloneHandler) Scan(ctx context.Context, path string) <-chan Entry
- func (h RCloneHandler) Write(ctx context.Context, path string, in io.Reader) (fs.Object, error)
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
var BackendMap = make(map[string]Backend)
var Backends []Backend
var ErrBackendNotSupported = errors.New("This backend is not supported")
var ErrGetUsageNotSupported = errors.New("The backend does not support getting usage quota")
var ErrMoveNotSupported = errors.New("The backend does not support moving files")
var ErrStorageNotAvailable = errors.New("storage not available")
Functions ¶
func GetHash ¶
GetHash computes the hash value of a given object based on the supported hash type by its filesystem. If the filesystem's hash computation is slow or if there is any error during hash computation, the function returns an empty string or an error respectively.
Parameters:
- ctx: A context to allow for timeout or cancellation of operations.
- object: An fs.ObjectInfo representing the object for which the hash needs to be computed.
Returns:
- The computed hash string of the object. If the filesystem's hash computation is considered slow or if there is an error in hash computation, an empty string is returned.
- An error if the function encounters any issues during its operation, such as failure in hash computation. If no error occurs, the error is nil.
func IsSameEntry ¶
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:
- 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.
- Retrieves the last modified time of 'object'.
- Identifies a supported hash type for the storage backend of 'object' and computes its hash value.
- The hash computation is skipped if the storage backend is a local file system or does not support any hash types.
- 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.
- 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.
- 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
type Entry ¶
Entry is a struct that represents a single file or directory during a data source scan.
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) <-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 ProviderOptions ¶
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 (RCloneHandler) Name ¶
func (h RCloneHandler) Name() string
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) (*model.StorageID, Writer, error)
GetRandomOutputWriter selects a storage from the provided storages list based on its available space and returns an associated Writer to interact with that storage.
The function works as follows:
- Iterates over each storage to obtain its usage information (free and total space).
- Calculates a weight for each storage based on its free space ratio.
- If the available space of a storage is below a threshold, it will not be considered for selection.
- Selects a storage based on its weight and returns the Writer for it.
Parameters:
- ctx: A context that allows for timeout or cancellation of operations.
- storages: A slice of storage models to choose from.
Returns:
- A pointer to the ID of the selected storage.
- A Writer object that can be used to write data to the selected storage.
- An error if the function encounters any issues during its operation or if no suitable storage is found. If all storages are full, it returns the ErrStorageNotAvailable error.