diskprune

package
v0.174.5 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diskprune reclaims explicitly disposable disk data, keeping process references, recent data, symlinks and checkouts intact.

Index

Constants

View Source
const CacheMinAge = time.Hour

CacheMinAge protects what a tool may still be writing: no cache unit written within it is removed, whatever its policy says.

Variables

This section is empty.

Functions

func Disposable

func Disposable(dir string, cutoff time.Time) (int64, string, error)

Disposable inspects every entry without following symlinks. An unknown directory, checkout, unreadable subtree or recent file is kept.

func InUse

func InUse(dir string, refs []string) bool

InUse reports whether a candidate contains a live reference, including references reached through a symlink. A reference to a parent alone does not make all its children busy.

func Measure added in v0.173.0

func Measure(path string) (int64, time.Time)

Measure is a directory's size and newest write, for reports.

func Remove

func Remove(dir string) error

Remove deletes disposable output through its parent root: an intervening symlink cannot redirect removal outside the candidate's parent.

Types

type CacheResult added in v0.173.0

type CacheResult struct {
	Result
	Held   int64
	Newest time.Time
}

CacheResult is one root's outcome: Held is what it held before, Newest its last write.

func Cache added in v0.173.0

func Cache(p Policy, now time.Time, pressure bool, refs, protect []string, dry bool) CacheResult

Cache trims root by p. A root that is a symbolic link, holds a protected path (the home, the state directory, a checkout root) or is itself a checkout is kept whole. A unit a process references, one holding a git checkout (work not yet committed or pushed included) or one written within CacheMinAge is kept; in files mode one reference or checkout inside the root keeps all of it. A dry run measures without writes.

type Policy added in v0.173.0

type Policy struct {
	Root        string
	Files       bool
	OlderThan   time.Duration
	MaxBytes    int64
	Regenerable bool
	// Nested are other policies' roots inside this one: each governs its
	// own subtree, which this policy neither counts nor removes.
	Nested []string
	// Recheck reads the processes' references again once the scan is done
	// and before anything is removed; an error keeps the whole root. Nil
	// keeps the references the call was given.
	Recheck func() ([]string, error)
}

Policy is one cache root's rule. In entries mode the root's direct children are the units, each removed whole; in files mode its regular files. A unit untouched for OlderThan goes; past MaxBytes the least recently written go until the root fits; under pressure a Regenerable cache drops every unit older than CacheMinAge.

type Result

type Result struct {
	Freed   int64
	Removed int
	Moved   int64
	Staged  int
	Kept    map[string]int
	Errors  []error
}

Result is one cleanup's measured bytes and keep/error reasons.

func Children

func Children(base string, cutoff time.Time, refs []string, dry bool) Result

Children prunes stale direct children only, never the containing directory.

func Output

func Output(dir string, cutoff time.Time, refs []string, dry bool) Result

Output reclaims a known output directory, refusing checkouts, active references and data newer than cutoff. A dry run measures without writes.

func Stage

func Stage(dir, trash string, now time.Time, refs []string, dry bool) Result

Stage moves build output into trash on the same filesystem. Moving does not free bytes. The new entry starts its retention window now, even when all the output's files are old. Cross-filesystem output is retained.

func (*Result) Add

func (r *Result) Add(other Result)

Add records another cleanup in the same report.

func (*Result) Keep

func (r *Result) Keep(why string)

Keep records a reason without naming private paths in the watch line.

Jump to

Keyboard shortcuts

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