Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/driver/wsl2/fs.go
2611 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package wsl2
5
6
import (
7
"context"
8
"errors"
9
"os"
10
"path/filepath"
11
12
"github.com/sirupsen/logrus"
13
14
"github.com/lima-vm/lima/v2/pkg/fileutils"
15
"github.com/lima-vm/lima/v2/pkg/limatype"
16
"github.com/lima-vm/lima/v2/pkg/limatype/filenames"
17
)
18
19
// EnsureFs downloads the root fs.
20
func EnsureFs(ctx context.Context, inst *limatype.Instance) error {
21
baseDisk := filepath.Join(inst.Dir, filenames.BaseDisk)
22
if _, err := os.Stat(baseDisk); errors.Is(err, os.ErrNotExist) {
23
var ensuredBaseDisk bool
24
errs := make([]error, len(inst.Config.Images))
25
for i, f := range inst.Config.Images {
26
if _, err := fileutils.DownloadFile(ctx, baseDisk, f.File, true, "the image", *inst.Config.Arch); err != nil {
27
errs[i] = err
28
continue
29
}
30
ensuredBaseDisk = true
31
break
32
}
33
if !ensuredBaseDisk {
34
return fileutils.Errors(errs)
35
}
36
}
37
logrus.Info("Download succeeded")
38
39
return nil
40
}
41
42