diskprune

package
v0.212.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 14 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 is wb disk prune (spec/features/disk-prune): it removes this user's old scratch from the temporary directory, and clears the Go build cache while no Go process runs. Nothing else is ever deleted.

Index

Constants

View Source
const (
	CategoryScratch = "scratch"
	CategoryBuild   = "go-build-cache"
)

Category names, as --category takes them.

View Source
const (
	StatusDelete  = "delete"
	StatusDeleted = "deleted"
	StatusKeep    = "keep"
	StatusSkipped = "skipped"
	StatusFailed  = "failed"
)

Statuses of items and categories.

View Source
const (
	OutcomeDone    = "done"
	OutcomePlanned = "planned"
	OutcomeSkipped = "skipped"
	OutcomeFailed  = "failed"
)

Outcomes of a run.

View Source
const DefaultScratchAge = 72 * time.Hour

DefaultScratchAge is how long nothing in a scratch directory may have changed before it is removed: comfortably past any running build or test.

Variables

Categories are the names --category accepts, in pruning order.

Functions

This section is empty.

Types

type CategoryReport

type CategoryReport struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Reason string `json:"reason,omitempty"`
	// Bytes is what the plan would free, or what apply freed.
	Bytes int64        `json:"bytes"`
	Items []ItemReport `json:"items,omitempty"`
	// Kept counts the directories left alone, by reason.
	Kept map[string]int `json:"kept,omitempty"`
}

CategoryReport is one category's plan or result.

type Env

type Env struct {
	// TempDirs are the resolved temporary directories (TMPDIR, GOTMPDIR).
	TempDirs []string
	UID      int
	Now      func() time.Time
	// GoCache is the resolved GOCACHE; GoCacheProblem says why there is
	// none prune may clear (GOCACHEPROG set, GOCACHE off or missing).
	GoCache        string
	GoCacheProblem string
	// GoCacheError is a failure to inspect the Go settings or the cache: a
	// finding, unlike a configuration with nothing to clear.
	GoCacheError string
	// GoCaches are the resolved GOCACHE and GOMODCACHE, which scratch never
	// removes even when they sit in the temporary directory.
	GoCaches []string
	// GoCachesUnknown says why the Go caches could not be located; scratch
	// then removes nothing.
	GoCachesUnknown string
	// MountPoints lists every mount point, so a scratch tree holding a bind
	// mount on its own filesystem is kept.
	MountPoints func() ([]string, error)
	// GoProcesses lists running Go tools, or fails when that cannot be told.
	GoProcesses func() ([]Process, error)
	// GoClean runs go clean -cache.
	GoClean func(ctx context.Context) error
	// Measure is the bytes removing path would free.
	Measure func(ctx context.Context, path string) int64
	// RemoveAll removes a directory tree without following symlinks.
	RemoveAll func(path string) error
}

Env is the machine prune works on, as fields so a test can describe any.

func NewEnv

func NewEnv() Env

NewEnv describes this machine. It runs nothing: Go's settings are read the way cmd/go reads them, without running go.

type ItemReport

type ItemReport struct {
	Path   string `json:"path"`
	Bytes  int64  `json:"bytes"`
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

ItemReport is one directory the category acts on.

type Options

type Options struct {
	Apply bool
	// Categories restricts the run; empty means every category.
	Categories []string
	// ScratchAge is the minimum quiet time of a scratch directory; zero
	// means DefaultScratchAge.
	ScratchAge time.Duration
}

Options is one invocation's selection.

type Process

type Process struct {
	PID     int
	Command string
}

Process is a running Go tool, for the report.

type Report

type Report struct {
	SchemaVersion int              `json:"schema_version"`
	Mode          string           `json:"mode"`
	Outcome       string           `json:"outcome"`
	Categories    []CategoryReport `json:"categories"`
}

Report is a run's result; --format json writes it as is.

func Run

func Run(ctx context.Context, env Env, o Options) Report

Run plans, and with o.Apply prunes, every selected category.

Jump to

Keyboard shortcuts

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