mediapresence

package
v0.9.0-dev.21 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mediapresence decides whether a media file is gone or only unreachable. A file is gone only when the filesystem says it does not exist and the bound media root holding it is present, readable and not empty: an unmounted share usually leaves an empty mountpoint, so an empty root reads as unreachable rather than as every file under it deleted. Any other failure, including a filesystem call that outlives the timeout, is a fault of the root; while one is recorded it is reported once at ERROR, as a persistent alert and as the media_root_unavailable gauge of that root.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideRoots = errors.New("path is outside every media root")

ErrOutsideRoots reports a path no bound media root contains, whose absence therefore proves nothing.

View Source
var ErrUnavailable = errors.New("media root unavailable")

ErrUnavailable matches every *UnavailableError.

Functions

This section is empty.

Types

type Checker

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

Checker is the process-wide judge of media file absence. It is safe for concurrent use.

func New

func New(cfg Config) (*Checker, error)

New builds a Checker; it fails only when Metrics or Alerts is missing, a nil pointer in either interface included.

func (*Checker) Bind

func (c *Checker) Bind(roots []string)

Bind installs the configured media roots. It runs on every activation: a new root's gauge starts at 0, and a removed root loses its fault, alert and series. Before the first Bind every path is outside the roots.

func (*Checker) Gone

func (c *Checker) Gone(ctx context.Context, path string) (bool, error)

Gone reports whether path definitely no longer exists. A false with a nil error means it exists. A non-nil error means nothing can be concluded and nothing may be deleted on its strength: ErrOutsideRoots, an *UnavailableError, or ctx's error when ctx ended first. While a root is faulted every path under it but the one that faulted it is unavailable, so only that path's check can clear the fault.

func (*Checker) Run

func (c *Checker) Run(ctx context.Context) error

Run rechecks every faulted root each RecheckInterval by judging the path that faulted it again, so a remounted share clears without waiting for that path's next caller. It blocks until ctx is done and returns ctx's error.

func (*Checker) Unavailable

func (c *Checker) Unavailable(path string) (root string, unavailable bool)

Unavailable reports the faulted root holding path, if any.

type Config

type Config struct {
	Metrics metrics
	Alerts  alerts
	Stat    func(path string) (fs.FileInfo, error) // nil: os.Stat
	// HasEntries reports whether a directory holds at least one entry; nil
	// reads one name.
	HasEntries      func(dir string) (bool, error)
	Timeout         time.Duration // 0: 10s, per filesystem call
	RecheckInterval time.Duration // 0: 5m, the background recheck period
}

Config configures a Checker. Metrics and Alerts are required; every other zero field takes its documented default.

type UnavailableError

type UnavailableError struct {
	Err  error
	Root string
	Path string
}

UnavailableError reports that Path could not be judged because Root, the bound root holding it, is faulted; Err is the failure that decided it.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

func (*UnavailableError) Unwrap

func (e *UnavailableError) Unwrap() []error

Unwrap exposes ErrUnavailable and the underlying error.

Jump to

Keyboard shortcuts

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