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
- Variables
- type DiskStats
- type DiskUsageCacher
- func (c *DiskUsageCacher) GetDiskUsage(s schema.Storage) (DiskStats, error)
- func (c *DiskUsageCacher) GetDiskUsageFresh(s schema.Storage) (DiskStats, error)
- func (c *DiskUsageCacher) HasEnoughFreeSpace(s schema.Storage, minFree uint64, fileSize uint64) (bool, error)
- func (c *DiskUsageCacher) Update() error
- type Handler
- func (f *Handler) Exists(path string) (bool, error)
- func (f *Handler) GetDiskUsage(s schema.Storage) (DiskStats, error)
- func (f *Handler) GetMoveables(ctx context.Context, share schema.Share, src schema.Storage, ...) ([]*schema.Moveable, error)
- func (f *Handler) HasEnoughFreeSpace(s schema.Storage, minFree uint64, fileSize uint64) (bool, error)
- func (f *Handler) IsEmptyFolder(path string) (bool, error)
- func (f *Handler) IsInUse(path string) bool
- type InUseChecker
Constants ¶
const ( // CheckerInterval is the interval at which the [InUseChecker] is updated. CheckerInterval = 5 * time.Second )
const ( // DiskUsageCacherInterval is the updating interval of the disk usage cache. DiskUsageCacherInterval = 3 * time.Second )
Variables ¶
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 DiskUsageCacher ¶
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) GetDiskUsage ¶
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 ¶
IsEmptyFolder is a helper function checking if a path is an empty folder.
type InUseChecker ¶
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.