Documentation
¶
Overview ¶
Package mediawrite owns every subtitle write into the media tree and the process-wide record of which destination folders refuse writes.
A write error marks its folder only when it reads as a folder fault and a probe of that folder (a real write of a hidden file, then a delete) fails too; any other refusal belongs to the one target. A marked folder blocks work under it until a probe or a write there succeeds, and while it is marked the condition is reported once at ERROR, as a persistent UI alert and as the media_root_unwritable gauge of its root.
Index ¶
- Variables
- type Config
- type PreflightRequest
- type UnwritableError
- type Writer
- func (w *Writer) Bind(roots []string, validate func(ctx context.Context, path string) error)
- func (w *Writer) Blocked(path string) (folder string, blocked bool)
- func (w *Writer) Preflight(ctx context.Context, req PreflightRequest) error
- func (w *Writer) RecheckInterval() time.Duration
- func (w *Writer) Run(ctx context.Context) error
- func (w *Writer) WriteFile(ctx context.Context, path string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrUnwritable = errors.New("media folder is not writable")
ErrUnwritable matches every *UnwritableError.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Metrics metrics
Alerts alerts
// Write writes one file; nil is atomicfile.WriteFile capped at MaxBytes,
// with no WithMode, so a subtitle gets the share's creation defaults.
// Probes and subtitle writes both go through it.
Write func(ctx context.Context, path string, data []byte) error
Remove func(path string) error // nil: os.Remove
Stat func(path string) (fs.FileInfo, error) // nil: os.Stat
Now func() time.Time // nil: time.Now
// MaxBytes caps every write; 0 means no cap.
MaxBytes int64
ProbeTimeout time.Duration // 0: 10s
ProbeTTL time.Duration // 0: 60s, how long a passing folder probe is reused
RecheckInterval time.Duration // 0: 5m, the background recheck period
}
Config configures a Writer. Metrics and Alerts are required; every other zero field takes its documented default.
type PreflightRequest ¶
type PreflightRequest struct {
// Folders are the folders scoped work will write into. Only entries
// inside a bound root are probed, with their known-bad ancestors and
// descendants; an entry the containment check refuses is skipped.
Folders []string
// Roots probes every bound root; the verdict depends only on them.
Roots bool
// RecheckBad also re-probes every known-bad folder, without letting a
// bad subfolder fail the verdict.
RecheckBad bool
// Raise re-creates a dismissed alert of a folder that still fails.
Raise bool
}
PreflightRequest selects what a Preflight probes before any provider work.
type UnwritableError ¶
UnwritableError reports a folder that refused a write or could not be proven writable. Op is "write", "probe" or "probe cleanup"; Err is the operating-system error or the probe timeout.
func (*UnwritableError) Error ¶
func (e *UnwritableError) Error() string
func (*UnwritableError) Unwrap ¶
func (e *UnwritableError) Unwrap() []error
Unwrap exposes ErrUnwritable and the underlying error.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is the process-wide media write guard. It is safe for concurrent use.
A bad folder's root is derived from the bound roots whenever it is read, so a Bind only swaps the roots and recomputes the alerts and gauges they imply. The logs, alerts and metric calls a state change decides go through queue, so they run after mu is released and in the order the state changed.
func New ¶
New builds a Writer; it fails only when Metrics or Alerts is missing, a nil pointer in either interface included.
func (*Writer) Bind ¶
Bind installs the configured media roots and the containment check that decides which requested folders may be probed. It runs on every activation: a new root's gauge starts at 0, a removed root loses its series, a bad folder resolves to the deepest new root containing it, and one no new root contains is dropped with its alert. It drops the passing probe cache; a probe already running finishes and settles against the state it finds. Before the first Bind every requested folder is refused.
func (*Writer) Blocked ¶
Blocked reports the deepest marked folder at or above path's folder, up to its root.
func (*Writer) Preflight ¶
func (w *Writer) Preflight(ctx context.Context, req PreflightRequest) error
Preflight probes the folders req names and returns nil, or the *UnwritableError of the first folder (by path) that decides the verdict and failed. With no media_roots bound it probes nothing and returns nil. A ctx that ends first returns ctx's error; a probe already started still runs to its own deadline and settles for the folder.
func (*Writer) RecheckInterval ¶
RecheckInterval is how often Run re-probes the marked folders.
func (*Writer) Run ¶
Run re-probes the known-bad folders every RecheckInterval, at most eight at once, so a folder recovers without a scan; a still-failing folder changes nothing. It blocks until ctx is done and returns ctx's error once the current round has returned. A probe step hung in the kernel outlives it: its goroutine ends when the call returns.