Documentation
¶
Overview ¶
Package diskusage measures a directory tree twice: the size it appears to occupy, and the size deleting it would actually reclaim.
The two figures differ whenever content is hard-linked. pnpm links every package file from its content-addressed store into each project's node_modules, so a worktree that reports 1.4 GB of node_modules may free a few megabytes when it is removed. Measured across one WB fleet sweep: 11.7 GB apparent against 5.9 GB unshared over the same set of worktrees. Reporting only the apparent figure promises a reclaim the deletion cannot deliver, which is why every size WB reports carries both.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Usage ¶
type Usage struct {
ApparentBytes int64 `json:"apparent_bytes"`
Files int64 `json:"files"`
// Unreadable counts entries the walk could not read, so the figures
// are a lower bound whenever it is not zero.
Unreadable int64 `json:"unreadable,omitempty"`
// FirstUnreadablePath and FirstUnreadableError are the first entry the
// walk could not read and why. They are not serialized here; wb disk
// reports them per root.
FirstUnreadablePath string `json:"-"`
FirstUnreadableError string `json:"-"`
}
Usage is one measured tree. ApparentBytes counts each inode's logical size once, the way `du --apparent-size` does. UnsharedBytes counts the physical blocks of the inodes whose every link lives inside the measured tree — the bytes removing the tree would return to the filesystem. SharedBytes is the apparent remainder: content the tree holds a link to but does not own.
type Walk ¶
type Walk struct {
// contains filtered or unexported fields
}
Walk measures several trees as one accounting unit.
Summing per-tree measurements is wrong across a fleet, and wrong in both directions. Two worktrees that hard-link the same pnpm store file each report its apparent size, so the total double-counts it; and when the only links to a file live in two measured worktrees, each tree calls it shared with something outside itself, so the total under-reports what removing both would return. A Walk answers the question a reclaim footer is actually asking — "how much comes back if I remove all of these?" — by counting every inode once and treating it as unshared exactly when every link to it is inside the selected set.
func (*Walk) Measure ¶
Measure measures one tree and records it in the walk. The returned Usage is that tree on its own, exactly as Measure reports it; the cross-tree figures come from Total.
func (*Walk) MeasureExcluding ¶
MeasureExcluding is Measure without the subtrees named in exclude. It exists for roots that contain another measured root — a retired home holding a checkout store — so each byte belongs to exactly one tree in the walk.