Files
w3cjandClaude Opus 5.5 f5cca0ff02 feat(images): devvm images and images rm
devvm images lists the images on every backend (IMAGE, FROM, DIGEST,
KEY, STATE current/stale/unfinished, SIZE, BACKEND), then the shared tool
images by the name images have them by (NAME, TOOL, VERSION, SIZE, VMS,
STATE current/in use/unused/not built/not installed). Listing never
resolves the tools lock. devvm images rm IMAGE|KEY... deletes images by
name (with --from, on that base) or by key, resolving every one first;
shared tools are refused.

- backend.Backend gets ImageSize (Lima: du of the instance folder);
  platform.DiskUsage counts blocks, hard links once.
- build: Listing, Delete, Image.Digest; ubuntu.ReleaseDate.
- tools: List, ReadLock (uses Lock.Version); vm: ToolsInUse,
  BackendUsed exported.
- Messages: reading_images, images_failed, images_rm_failed,
  deleted_image, no_image_named, no_image_named_from,
  tools_not_images_rm.
- Tests: testdata/script/images.txtar (images.bats' three images cases
  and images rm), Go tests for Listing, Delete, List, compareVersions,
  DiskUsage, ImageSize, ReleaseDate, humanSize; e2e images section lists
  base and a layer, deletes by name and an unfinished build by key.
- Docs: images.md (Listing images, Deleting images), commands.md, the
  CLI reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 20:42:39 -06:00

34 lines
715 B
Go

package platform
import (
"io/fs"
"path/filepath"
)
// DiskUsage is the disk space a file, or a folder and everything in it,
// takes, as du counts it: each file's blocks, a file with several links
// once. Links aren't followed. Blocks a copy-on-write clone shares with
// its original count for both.
func DiskUsage(path string) (int64, error) {
var n int64
seen := map[string]bool{}
err := filepath.WalkDir(path, func(_ string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
fi, err := d.Info()
if err != nil {
return err
}
if id := DevIno(fi); id != "" {
if seen[id] {
return nil
}
seen[id] = true
}
n += allocated(fi)
return nil
})
return n, err
}