func ensureNerdctlArchiveCache(y *limayaml.LimaYAML) (string, error) {
	if !*y.Containerd.System && !*y.Containerd.User {
		return "", nil
	}
	errs := make([]error, len(y.Containerd.Archives))
	for i := range y.Containerd.Archives {
		f := &y.Containerd.Archives[i]
		if f.Arch != y.Arch {
			errs[i] = fmt.Errorf("unsupported arch: %q", f.Arch)
			continue
		}
		logrus.WithField("digest", f.Digest).Infof("Attempting to download the nerdctl archive from %q", f.Location)
		res, err := downloader.Download("", f.Location, downloader.WithCache(), downloader.WithExpectedDigest(f.Digest))
		if err != nil {
			errs[i] = fmt.Errorf("failed to download %q: %w", f.Location, err)
			continue
		}
		switch res.Status {
		case downloader.StatusDownloaded:
			logrus.Infof("Downloaded the nerdctl archive from %q", f.Location)
		case downloader.StatusUsedCache:
			logrus.Infof("Using cache %q", res.CachePath)
		default:
			logrus.Warnf("Unexpected result from downloader.Download(): %+v", res)
		}
		if res.CachePath == "" {
			if downloader.IsLocal(f.Location) {
				return f.Location, nil
			}
			return "", fmt.Errorf("cache did not contain %q", f.Location)
		}
		return res.CachePath, nil
	}
	return "", fmt.Errorf("failed to download the nerdctl archive, attempted %d candidates, errors=%v",
		len(y.Containerd.Archives), errs)
}
ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-linux-GOARCH.tar.gz archive
into the cache before launching the hostagent process, so that we can show the progress in tty.
https://github.com/lima-vm/lima/issues/326
package start
import (
	"context"
	"errors"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"time"
	"github.com/lima-vm/lima/pkg/downloader"
	hostagentevents "github.com/lima-vm/lima/pkg/hostagent/events"
	"github.com/lima-vm/lima/pkg/limayaml"
	"github.com/lima-vm/lima/pkg/qemu"
	"github.com/lima-vm/lima/pkg/store"
	"github.com/lima-vm/lima/pkg/store/filenames"
	"github.com/sirupsen/logrus"
)
func ensureDisk(ctx context.Context, instName, instDir string, y *limayaml.LimaYAML) error {
	qCfg := qemu.Config{
		Name:        instName,
		InstanceDir: instDir,
		LimaYAML:    y,
	}
	if err := qemu.EnsureDisk(qCfg); err != nil {
		return err
	}
	return nil
}