Skip to content

Commit ea0b87f

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

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

pkg/cidata/cidata.go

+7-18
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,18 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
339339
}
340340
}
341341

342-
guestAgentBinary, err := GuestAgentBinary(*y.OS, *y.Arch)
342+
guestAgentBinary, err := usrlocalsharelima.GuestAgentBinary(*y.OS, *y.Arch)
343343
if err != nil {
344344
return err
345345
}
346-
defer guestAgentBinary.Close()
346+
guestAgent, err := os.Open(guestAgentBinary)
347+
if err != nil {
348+
return err
349+
}
350+
defer guestAgent.Close()
347351
layout = append(layout, iso9660util.Entry{
348352
Path: "lima-guestagent",
349-
Reader: guestAgentBinary,
353+
Reader: guestAgent,
350354
})
351355

352356
if nerdctlArchive != "" {
@@ -373,21 +377,6 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
373377
return iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout)
374378
}
375379

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

pkg/usrlocalsharelima/usrlocalsharelima.go

+14
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)