Skip to content

Commit 47be1ef

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

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
@@ -338,14 +338,18 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
338338
}
339339
}
340340

341-
guestAgentBinary, err := GuestAgentBinary(*y.OS, *y.Arch)
341+
guestAgentBinary, err := usrlocalsharelima.GuestAgentBinary(*y.OS, *y.Arch)
342342
if err != nil {
343343
return err
344344
}
345-
defer guestAgentBinary.Close()
345+
guestAgent, err := os.Open(guestAgentBinary)
346+
if err != nil {
347+
return err
348+
}
349+
defer guestAgent.Close()
346350
layout = append(layout, iso9660util.Entry{
347351
Path: "lima-guestagent",
348-
Reader: guestAgentBinary,
352+
Reader: guestAgent,
349353
})
350354

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

375-
func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (io.ReadCloser, error) {
376-
if ostype == "" {
377-
return nil, errors.New("os must be set")
378-
}
379-
if arch == "" {
380-
return nil, errors.New("arch must be set")
381-
}
382-
dir, err := usrlocalsharelima.Dir()
383-
if err != nil {
384-
return nil, err
385-
}
386-
gaPath := filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch)
387-
return os.Open(gaPath)
388-
}
389-
390379
func getCert(content string) Cert {
391380
lines := []string{}
392381
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)