Help us shape the future of Go! Take the 2026 Go Developer Survey

disk

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 17 Imported by: 0

Documentation

Overview

Package disk is a storage-attribution diagnostic for StageFreight: it answers "what operational entity (project / registry / runtime) is consuming disk today" rather than "what folders exist". Scanners build a graph of sized Nodes carrying attribution edges; the renderer and the by-project / reclaim views are projections of that one graph. Read-only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCacheRoot

func DefaultCacheRoot() string

DefaultCacheRoot is the persistent mount as seen inside a CI job container (/stagefreight). On a runner host it is mounted elsewhere (e.g. /opt/docker/gitlab-runner/stagefreight) — pass that to ScanCacheMount.

func DiscoverCacheRoot

func DiscoverCacheRoot() string

DiscoverCacheRoot locates the persistent cache mount when --cache is not given: the container default (/stagefreight) or, on a runner host, a `…/stagefreight` directory carrying toolchains/ + cache/. Returns "" if none found. (Reading a runner's root-owned mount needs sudo.)

func Render

func Render(w io.Writer, host string, r *Report, opt RenderOpts)

Render writes the full human diagnostic for r.

Types

type Attribution

type Attribution struct {
	Project  string // dragonfly, stagefreight, jetpack
	Registry string // ghcr.io, cr.pcfae.com, docker.io
	Runtime  string // cache-mount, docker-host, docker-dind, repo-tree
	Tool     string // go, rust, trivy
}

Attribution links a storage node to operational entities — the projection axes. Empty fields mean "not attributable on this dimension".

type FS

type FS struct {
	Path  string
	Total int64
	Free  int64
}

FS is the filesystem context the whole report is scaled against.

type Flag

type Flag uint8

Flag marks a node for the two operator-facing concerns: attention and reclaim.

const (
	FlagAttention   Flag = 1 << iota // ⚠ smelly / stale / proliferating
	FlagReclaimable                  // ♻ safe (or safe-after-inspect) to delete
)

func (Flag) Has

func (f Flag) Has(x Flag) bool

type Hint

type Hint struct {
	Command string // "docker buildx prune"
	Safety  string // "safe", "inspect first", "rebuilds"
}

Hint is the reclaim action surfaced in the ledger.

type Node

type Node struct {
	Label string
	Path  string // absolute, when backed by the filesystem
	Bytes int64  // self + descendants
	Note  string // inline diagnosis: versions, tags, "×6 · avg 1.0G"
	Attr  Attribution
	Flags Flag
	Hint  *Hint
	Kids  []*Node
}

Node is one sized location in the graph. Everything is the same shape:

label · TOTAL · note   →   children (biggest-first)

func ScanCacheMount

func ScanCacheMount(root string) *Node

ScanCacheMount builds the CACHE MOUNT domain from <root>/cache (rebuildable build/scan caches) and <root>/toolchains (versioned tool installs). Returns nil if neither exists.

func ScanDocker

func ScanDocker(ctx context.Context) *Node

ScanDocker queries reachable Docker daemons and returns the DOCKER domain, or nil if none reachable. The default socket is the "host" daemon. A "dind" CI-build daemon is reached either via DOCKER_HOST or by auto-discovering a running docker:dind container and querying it through `docker exec`.

func ScanRepos

func ScanRepos(roots []string, maxDepth int) *Node

ScanRepos discovers git repos under roots (≤maxDepth deep) and sizes each at the repo-dir level, biggest-first. Returns nil if none found.

type ProjectRow

type ProjectRow struct {
	Project string
	Bytes   int64
	Parts   []*Node // the contributing nodes, biggest-first
}

ProjectRow is one line of the by-project projection.

type RenderOpts

type RenderOpts struct {
	MaxKids  int // collapse a node's children beyond this into "+ N more" (0 → 8)
	BarWidth int // 0 → 16
}

RenderOpts tunes child caps and bar width. Zero value = the default summary.

type Report

type Report struct {
	FS      FS
	Domains []*Node
}

Report is the assembled graph: top-level domains under an implicit root.

func Scan

func Scan(ctx context.Context, cacheRoot string, repoRoots []string, maxDepth int) *Report

Scan assembles the full report: the cache mount, the Docker daemon(s), and discovered repositories. The three domains are independent, so they run concurrently — wall-clock is the slowest single domain, not their sum. Any domain that finds nothing is omitted. (Docker carries ctx's deadline and starts at t=0 alongside the walks, so the slow cache walk can't starve it.)

func (*Report) ByProject

func (r *Report) ByProject() []ProjectRow

ByProject groups attributed nodes by project. Attribution emerges from independent scanners agreeing on the project key — nobody computes the rollup.

func (*Report) Reclaimable

func (r *Report) Reclaimable() []*Node

Reclaimable is the reclaim-ledger projection: every node flagged reclaimable, biggest-first, deduplicated to the highest reclaimable ancestor (we never list both a parent and its child).

func (*Report) Total

func (r *Report) Total() int64

Total sums the domains (note: domains can overlap the same filesystem, so this is an attribution total, not a disk-occupancy total).

Jump to

Keyboard shortcuts

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