mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
36 lines
929 B
Go
36 lines
929 B
Go
package platform
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestDiskUsage(t *testing.T) {
|
|
dir := t.TempDir()
|
|
a := filepath.Join(dir, "a")
|
|
if err := os.WriteFile(a, make([]byte, 64<<10), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
one, err := DiskUsage(dir)
|
|
if err != nil || one < 64<<10 {
|
|
t.Fatalf("DiskUsage = %d, %v; want at least 64 KiB", one, err)
|
|
}
|
|
// A second link to it, and a symlink, take nothing more.
|
|
if err := os.Link(a, filepath.Join(dir, "b")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink("/", filepath.Join(dir, "c")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
two, err := DiskUsage(dir)
|
|
if err != nil || two > one+64<<10-1 {
|
|
t.Errorf("with a hard link and a symlink: DiskUsage = %d, %v; want about %d", two, err, one)
|
|
}
|
|
if _, err := DiskUsage(filepath.Join(dir, "nope")); !errors.Is(err, fs.ErrNotExist) {
|
|
t.Errorf("a missing path: err = %v, want fs.ErrNotExist", err)
|
|
}
|
|
}
|