Skip to content

Commit

Permalink
Move open and gzip back to cidata again
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jun 30, 2024
1 parent 3d495ed commit fa19eff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
20 changes: 17 additions & 3 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cidata

import (
"compress/gzip"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -345,14 +346,27 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
if err != nil {
return err
}
guestAgent, err := usrlocalsharelima.Open(guestAgentBinary)
if err != nil {
var reader io.ReadCloser
guestAgent, err := os.Open(guestAgentBinary)
if errors.Is(err, os.ErrNotExist) {
guestAgent, err = os.Open(guestAgentBinary + ".gz")
if err != nil {
return err
}
logrus.Debugf("Decompressing %s.gz", guestAgentBinary)
reader, err = gzip.NewReader(guestAgent)
if err != nil {
return err
}
} else if err != nil {
return err
} else {
reader = guestAgent
}
defer guestAgent.Close()
layout = append(layout, iso9660util.Entry{
Path: "lima-guestagent",
Reader: guestAgent,
Reader: reader,
})

if nerdctlArchive != "" {
Expand Down
19 changes: 0 additions & 19 deletions pkg/usrlocalsharelima/usrlocalsharelima.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package usrlocalsharelima

import (
"compress/gzip"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"runtime"

"github.com/lima-vm/lima/pkg/limayaml"
"github.com/sirupsen/logrus"
)

func Dir() (string, error) {
Expand Down Expand Up @@ -82,19 +79,3 @@ func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (string, error) {
}
return filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch), nil
}

func Open(path string) (io.ReadCloser, error) {
reader, err := os.Open(path)
if errors.Is(err, os.ErrNotExist) {
reader, err := os.Open(path + ".gz")
if err != nil {
return nil, err
}
logrus.Debugf("Decompressing %s.gz", path)
return gzip.NewReader(reader)
}
if err != nil {
return nil, err
}
return reader, nil
}

0 comments on commit fa19eff

Please sign in to comment.