Skip to content

Commit ce3c041

Browse files
committed
Move GuestAgentBinary to usrlocalsharelima
Signed-off-by: Anders F Björklund <[email protected]>
1 parent d58e833 commit ce3c041

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

pkg/cidata/cidata.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,18 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
341341
}
342342
}
343343

344-
guestAgentBinary, err := GuestAgentBinary(*y.OS, *y.Arch)
344+
guestAgentBinary, err := usrlocalsharelima.GuestAgentBinary(*y.OS, *y.Arch)
345345
if err != nil {
346346
return err
347347
}
348-
defer guestAgentBinary.Close()
348+
guestAgent, err := os.Open(guestAgentBinary)
349+
if err != nil {
350+
return err
351+
}
352+
defer guestAgent.Close()
349353
layout = append(layout, iso9660util.Entry{
350354
Path: "lima-guestagent",
351-
Reader: guestAgentBinary,
355+
Reader: guestAgent,
352356
})
353357

354358
if nerdctlArchive != "" {
@@ -375,21 +379,6 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
375379
return iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout)
376380
}
377381

378-
func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (io.ReadCloser, error) {
379-
if ostype == "" {
380-
return nil, errors.New("os must be set")
381-
}
382-
if arch == "" {
383-
return nil, errors.New("arch must be set")
384-
}
385-
dir, err := usrlocalsharelima.Dir()
386-
if err != nil {
387-
return nil, err
388-
}
389-
gaPath := filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch)
390-
return os.Open(gaPath)
391-
}
392-
393382
func getCert(content string) Cert {
394383
lines := []string{}
395384
for _, line := range strings.Split(content, "\n") {

pkg/usrlocalsharelima/usrlocalsharelima.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ func Dir() (string, error) {
6060
return "", fmt.Errorf("failed to find \"lima-guestagent.%s-%s\" binary for %q, attempted %v",
6161
ostype, arch, self, gaCandidates)
6262
}
63+
64+
func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (string, error) {
65+
if ostype == "" {
66+
return "", errors.New("os must be set")
67+
}
68+
if arch == "" {
69+
return "", errors.New("arch must be set")
70+
}
71+
dir, err := Dir()
72+
if err != nil {
73+
return "", err
74+
}
75+
return filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch), nil
76+
}

0 commit comments

Comments
 (0)