filesystem

package
v0.0.0-...-7b13daf Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package filesystem implements routines for translating filesystem elements into schema.Moveable (by walking the filesystem), as well as helper routines relating to information collection on associated filesystems.

Index

Constants

View Source
const (
	// CheckerInterval is the interval at which the [InUseChecker] is updated.
	CheckerInterval = 5 * time.Second
)
View Source
const (
	// DiskUsageCacherInterval is the updating interval of the disk usage cache.
	DiskUsageCacherInterval = 3 * time.Second
)

Variables

View Source
var (
	// ErrNilDestination is an error that occurs when a [schema.Moveable]
	// destination is attempted to be accessed but is in fact nil.
	ErrNilDestination = errors.New("destination is nil")

	// ErrInvalidFileSize is an error that occurs when a given filesize is
	// smaller than 0 and impossible to handle in the respective function.
	ErrInvalidFileSize = errors.New("invalid file size < 0")
)

Functions

This section is empty.

Types

type DiskStats

type DiskStats struct {
	TotalSize uint64
	FreeSpace uint64
}

DiskStats holds disk usage information. It is meant to be passed by value.

type DiskUsageCacher

type DiskUsageCacher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DiskUsageCacher caches disk usage information in a thread-safe manner.

func NewDiskUsageCacher

func NewDiskUsageCacher(ctx context.Context, unixHandler unixStatfsProvider) *DiskUsageCacher

NewDiskUsageCacher returns a pointer to a new DiskUsageCacher. The update method is started, refreshing the cached data every DiskUsageCacherInterval.

func (*DiskUsageCacher) GetDiskUsage

func (c *DiskUsageCacher) GetDiskUsage(s schema.Storage) (DiskStats, error)

GetDiskUsage gets the cached DiskStats for a schema.Storage. If none are cached, fresh ones are retrieved and cached using DiskUsageCacher.GetDiskUsageFresh.

func (*DiskUsageCacher) GetDiskUsageFresh

func (c *DiskUsageCacher) GetDiskUsageFresh(s schema.Storage) (DiskStats, error)

GetDiskUsageFresh calls [DiskUsageCacher.getDiskUsageFromOS] for a specific schema.Storage. The result is stored in the DiskUsageCacher's cache for later retrieval/periodic updating.

func (*DiskUsageCacher) HasEnoughFreeSpace

func (c *DiskUsageCacher) HasEnoughFreeSpace(s schema.Storage, minFree uint64, fileSize uint64) (bool, error)

HasEnoughFreeSpace is a helper method that allows checking if a certain schema.Storage can house a certain fileSize without exceeding a certain minFree threshold (uses caching).

func (*DiskUsageCacher) Update

func (c *DiskUsageCacher) Update() error

Update calls [DiskUsageCacher.getDiskUsageFromOS] on all cached schema.Storage. This means that the cache is refreshed with new disk usage statistics from the OS.

type Handler

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

Handler is the principal implementation for the filesystem services.

func NewHandler

func NewHandler(ctx context.Context, osHandler osProvider, unixHandler unixProvider) (*Handler, error)

NewHandler returns a pointer to a new filesystem Handler.

func (*Handler) Exists

func (f *Handler) Exists(path string) (bool, error)

Exists is a helper function checking if a path already exists.

func (*Handler) GetDiskUsage

func (f *Handler) GetDiskUsage(s schema.Storage) (DiskStats, error)

GetDiskUsage gets DiskStats for a schema.Storage, wrapping the previously given [diskStatProvider] implementation's respective function.

func (*Handler) GetMoveables

func (f *Handler) GetMoveables(ctx context.Context, share schema.Share, src schema.Storage, dst schema.Storage) ([]*schema.Moveable, error)

GetMoveables returns all schema.Moveable candidates for a schema.Share on a schema.Storage.

It is the principal method used for retrieving all schema.Moveable and their subelements for a schema.Share on a schema.Storage, including referencing any hard- and symlinks, establishing metadata, as well as directory structure with parent/child relations for later allocation/recreation.

For convenience, a destination schema.Storage can be set here, if it is already known at the time. An example case would be directly allocating to one schema.Pool instead of multiple schema.Disk.

func (*Handler) HasEnoughFreeSpace

func (f *Handler) HasEnoughFreeSpace(s schema.Storage, minFree uint64, fileSize uint64) (bool, error)

HasEnoughFreeSpace allows checking if a certain schema.Storage can house a certain fileSize without exceeding a certain minFree threshold. For this it wraps the function of the previously given [diskStatProvider] implementation.

func (*Handler) IsEmptyFolder

func (f *Handler) IsEmptyFolder(path string) (bool, error)

IsEmptyFolder is a helper function checking if a path is an empty folder.

func (*Handler) IsInUse

func (f *Handler) IsInUse(path string) bool

IsInUse checks if a file is in use by another process of the operating system. For this it wraps the function of the given [inUseProvider] implementation.

type InUseChecker

type InUseChecker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

InUseChecker caches paths which are currently in use by another process of the operating system. This allows for fast checks if a given path is in use, without overloading the OS with syscalls.

func NewInUseChecker

func NewInUseChecker(ctx context.Context, osHandler osProvider) (*InUseChecker, error)

NewInUseChecker returns a pointer to a new InUseChecker. The update method is started, querying the OS for in-use paths every CheckerInterval.

func (*InUseChecker) IsInUse

func (c *InUseChecker) IsInUse(path string) bool

IsInUse checks (the cache) if a path is currently in use by another process of the operating system.

func (*InUseChecker) Update

func (c *InUseChecker) Update() error

Update queries the operating system for all in-use paths and stores them in the InUseChecker cache. Since this is a time and resource intensive operation, this method is a no-op with an update in progress.

Jump to

Keyboard shortcuts

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