@@ -34,14 +34,21 @@ const DefaultWatchHostAgentEventsTimeout = 10 * time.Minute
34
34
// ensureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-GOOS-GOARCH.tar.gz archive
35
35
// into the cache before launching the hostagent process, so that we can show the progress in tty.
36
36
// https://github.com/lima-vm/lima/issues/326
37
- func ensureNerdctlArchiveCache (y * limayaml.LimaYAML ) (string , error ) {
37
+ func ensureNerdctlArchiveCache (y * limayaml.LimaYAML , start bool ) (string , error ) {
38
38
if ! * y .Containerd .System && ! * y .Containerd .User {
39
39
// nerdctl archive is not needed
40
40
return "" , nil
41
41
}
42
42
43
43
errs := make ([]error , len (y .Containerd .Archives ))
44
44
for i , f := range y .Containerd .Archives {
45
+ // Skip downloading again if the file is already in the cache
46
+ if start && f .Arch == * y .Arch && ! downloader .IsLocal (f .Location ) {
47
+ path , err := fileutils .CachedFile (f )
48
+ if err == nil {
49
+ return path , nil
50
+ }
51
+ }
45
52
path , err := fileutils .DownloadFile ("" , f , false , "the nerdctl archive" , * y .Arch )
46
53
if err != nil {
47
54
errs [i ] = err
@@ -65,7 +72,7 @@ type Prepared struct {
65
72
}
66
73
67
74
// Prepare ensures the disk, the nerdctl archive, etc.
68
- func Prepare (_ context.Context , inst * store.Instance ) (* Prepared , error ) {
75
+ func Prepare (_ context.Context , inst * store.Instance , start bool ) (* Prepared , error ) {
69
76
y , err := inst .LoadYAML ()
70
77
if err != nil {
71
78
return nil , err
@@ -83,7 +90,7 @@ func Prepare(_ context.Context, inst *store.Instance) (*Prepared, error) {
83
90
if err := limaDriver .CreateDisk (); err != nil {
84
91
return nil , err
85
92
}
86
- nerdctlArchiveCache , err := ensureNerdctlArchiveCache (y )
93
+ nerdctlArchiveCache , err := ensureNerdctlArchiveCache (y , start )
87
94
if err != nil {
88
95
return nil , err
89
96
}
@@ -116,7 +123,7 @@ func Start(ctx context.Context, inst *store.Instance) error {
116
123
}
117
124
}
118
125
119
- prepared , err := Prepare (ctx , inst )
126
+ prepared , err := Prepare (ctx , inst , true )
120
127
if err != nil {
121
128
return err
122
129
}
0 commit comments