# gc: deletes what devvm images lists as stale or unfinished, the tool # images it lists as unused, older versions of devvm's mise and what of the # package cache no base needs, after # listing them; not a terminal, so it doesn't ask. Never a project VM (one named like an image included), # a current image, or a tool image a VM's state lists. env IMAGES=$XDG_DATA_HOME/devvm/images env SHARE=$XDG_DATA_HOME/devvm/tools # Nothing built. exec devvm gc --force stdout '^==> nothing_to_clean$' ! stderr . # base, foo on it and claude's tools; then foo is edited (stale), and # there's a build that didn't finish, an image whose record is corrupt, # one without a key's shape, and project VMs, one from a folder named # img-foo. mkdir $XDG_CONFIG_HOME/devvm/layers cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh exec devvm build foo # claude's tools, built for a VM with Claude Code, deleted since. project agentvm exec devvm --network open --no-git-protect --tools none --agents claude exec devvm rm --force --no-export cd $WORK exec sh -c 'for i in base foo; do grep -lxF " \"name\": \"$i\"," "$IMAGES"/*/record.json | xargs dirname | xargs basename > "$i.key"; done' exec sh -c 'echo "# edited" >> "$XDG_CONFIG_HOME/devvm/layers/foo.sh"' exec sh -c 'for vm in devvm-img-000000000000 devvm-img-111111111111 devvm-img-node devvm-img-foo-12345612345601 devvm-web-12345612345602; do stub vm "$vm" Stopped; done' mkdir $IMAGES/111111111111 exec sh -c 'echo "not a record" > "$IMAGES/111111111111/record.json"' # Tool images: claude's (current), an old go a VM lists, one a VM that's # gone outside devvm still lists in its state, and an old one nothing # lists, with its record. exec sh -c 'cd "$SHARE" && for f in go-1.20.0 go-1.19.0 go-1.9.0; do echo x > $f-0123456789ab.erofs; done' json_set $SHARE/go-1.20.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z json_set $SHARE/go-1.19.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z json_set $SHARE/go-1.9.0-0123456789ab.erofs.json sha256=x libc=gnu backend=lima built=2020-01-01T00:00:00Z mkdir $VMS/12345612345603 $VMS/12345612345604 json_set $VMS/12345612345603/vm.json version:=1 id=x name=devvm-p-12345612345603 image=go dir=/p backend=lima tools.made.files:=["go-1.20.0-0123456789ab.erofs"] json_set $VMS/12345612345604/vm.json version:=1 id=y name=devvm-gone-12345612345604 image=go dir=/q backend=lima tools.made.files:=["go-1.19.0-0123456789ab.erofs"] # The builds wrote none of devvm's own files out: they stay in the binary. ! exists $XDG_DATA_HOME/devvm/assets # devvm's own mise: an older version, and one another devvm is # downloading (it changed just now). mkdir $XDG_DATA_HOME/devvm/cache/mise/2020.1.1 $XDG_DATA_HOME/devvm/cache/mise/2099.1.1 exec touch -t 202001010000 $XDG_DATA_HOME/devvm/cache/mise/2020.1.1 # devvm images says how many images gc deletes, and what it frees. exec devvm images stdout '^foo .* stale ' stderr '^images_stale_note count=4$' stderr '^images_unused size=\S+$' stub_reset exec devvm gc --force stdout '^gc_images\n' stdout '^gc_image image=foo key=[0-9a-f]{12}$' stdout '^gc_unfinished key=000000000000$' stdout '^gc_unfinished key=111111111111$' stdout '^gc_unfinished key=node$' stdout '^gc_tools count=1 size=\S+$' stdout '^gc_mise count=1 size=\S+$' stdout '^==> deleted_mise count=1$' ! exists $XDG_DATA_HOME/devvm/cache/mise/2020.1.1 exists $XDG_DATA_HOME/devvm/cache/mise/2099.1.1 stdout -count=1 '^==> deleted_image ' stdout -count=3 '^==> deleted_unfinished_build ' stdout '^==> deleted_tools count=1$' ! stdout 'image=base' exec sh -c 'grep "^limactl delete" "$STUB_LOG" | sort' cp stdout deleted exec sh -c 'printf "limactl delete -f devvm-img-%s\n" 000000000000 111111111111 "$(cat foo.key)" node | sort' cmp stdout deleted # What's left: base, the project VMs and their records; the tool images # that are current or listed; nothing in the share is locked. exec sh -c 'stub vms | grep -c .' stdout '^3$' exec sh -c 'v=$WORK/vms; stub vms > "$v" && grep -q "^devvm-img-$(cat base.key) " "$v" && grep -q "^devvm-img-foo-12345612345601" "$v" && grep -q "^devvm-web-12345612345602" "$v"' exec sh -c 'test -f "$IMAGES/$(cat base.key)/record.json" && ! test -e "$IMAGES/$(cat foo.key)" && ! test -e "$IMAGES/111111111111"' ! exists $SHARE/go-1.9.0-0123456789ab.erofs ! exists $SHARE/go-1.9.0-0123456789ab.erofs.json exists $SHARE/go-1.20.0-0123456789ab.erofs exists $SHARE/go-1.19.0-0123456789ab.erofs exec sh -c 'ls "$SHARE"/claude-*.erofs' ! exists $SHARE/.lock # Again: nothing left, and devvm images says only the total. exec devvm gc --force stdout '^==> nothing_to_clean$' exec devvm images stderr '^images_total size=\S+$' ! stderr 'images_stale_note|images_unused' # The package cache: the set of a base the backend no longer has goes, and # with it the file only it names, as does a file no set names; so does a # build's folder of what it gave back once it's a day old, but not a new one. env PKGS=$XDG_DATA_HOME/devvm/packages env A=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa env B=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb mkdir $PKGS/sets $PKGS/.taken-old $PKGS/.taken-new exec sh -c 'echo x > "$PKGS/$A.deb" && echo y > "$PKGS/$B.deb" && touch -t 202001010000 "$PKGS/.taken-old"' exec sh -c 'printf "{\"recorded\": \"2020-01-01T00:00:00Z\", \"packages\": [{\"name\": \"a\", \"version\": \"1\", \"arch\": \"arm64\", \"sha256\": \"%s\", \"size\": 2, \"entry\": \"Package: a\"}]}\n" "$A" > "$PKGS/sets/222222222222.json"' exec devvm gc --force stdout '^gc_packages count=2 size=\S+$' stdout '^==> deleted_packages count=2$' ! exists $PKGS/sets/222222222222.json ! exists $PKGS/$A.deb ! exists $PKGS/$B.deb ! exists $PKGS/.taken-old exists $PKGS/.taken-new exec devvm gc --force stdout '^==> nothing_to_clean$' -- foo.sh -- #!/bin/bash echo foo