Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNamespace = errorx.NewNamespace("filepruner") ErrPruneFailed = ErrNamespace.NewType("prune_failed") ErrNoTimestamp = ErrNamespace.NewType("no_timestamp") )
Functions ¶
This section is empty.
Types ¶
type FileSizeStrategy ¶
type FileSizeStrategy struct {
MaxBytes int64
}
FileSizeStrategy prunes files whose size exceeds MaxBytes. Useful for unbounded append-only files that have no age-based retention policy.
func (FileSizeStrategy) ShouldPrune ¶
func (s FileSizeStrategy) ShouldPrune(path string) (bool, error)
ShouldPrune returns true if the file's size exceeds MaxBytes.
type FilenameTimestampStrategy ¶
FilenameTimestampStrategy prunes files whose timestamp embedded in the filename is older than MaxAge. The timestamp is extracted using the provided Layout (Go time format string), e.g. "20060102T150405Z" for compact ISO-8601 with UTC suffix. Intended for per-operation files such as "consensus-upgrade-20260415T143000Z-v0.75.0.jsonl". Files with no parseable timestamp are not pruned.
func (FilenameTimestampStrategy) ShouldPrune ¶
func (s FilenameTimestampStrategy) ShouldPrune(path string) (bool, error)
ShouldPrune returns true if the timestamp embedded in the filename predates now-MaxAge. Returns an error if Layout is empty (an empty layout causes time.Parse to match any empty substring, making every file appear timestamped).
type ModTimeStrategy ¶
ModTimeStrategy prunes files whose modification time is older than MaxAge. Suitable for files that do not embed a timestamp in their name.
func (ModTimeStrategy) ShouldPrune ¶
func (s ModTimeStrategy) ShouldPrune(path string) (bool, error)
ShouldPrune returns true if the file's ModTime predates now-MaxAge.
type Pruner ¶
type Pruner struct {
// contains filtered or unexported fields
}
Pruner removes files matching a glob pattern according to a strategy-driven age filter followed by a hard-cap limit.
func (*Pruner) Prune ¶
Prune applies the retention policy to files matching glob in dir:
- Files for which the strategy returns ShouldPrune=true are removed.
- If more than keep eligible files remain after step 1, the first entries in ascending filename order are removed until the cap is satisfied. Files whose eligibility could not be determined (strategy returned an error) are never removed — neither in step 1 nor by the cap pass.
Files are sorted ascending by name before both passes. For strategies that embed a timestamp in the filename (e.g. FilenameTimestampStrategy) this preserves chronological order; for other strategies it is an arbitrary but stable order.
Returns a combined error if any deletion fails, so partial pruning is visible to the caller rather than silently violating the retention contract.
type Strategy ¶
Strategy decides whether a file is a candidate for pruning. If ShouldPrune returns an error the file is treated as protected: it is kept by both the strategy pass and the hard-cap pass. The pruner will never delete a file whose eligibility cannot be determined.