Skip to content

Commit 1b54ed4

Browse files
committed
Move open and gzip back to cidata again
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 3d495ed commit 1b54ed4

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

pkg/cidata/cidata.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cidata
22

33
import (
4+
"compress/gzip"
45
"errors"
56
"fmt"
67
"io"
@@ -345,9 +346,21 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
345346
if err != nil {
346347
return err
347348
}
348-
guestAgent, err := usrlocalsharelima.Open(guestAgentBinary)
349+
var guestAgent io.ReadCloser
350+
guestAgent, err = os.Open(guestAgentBinary)
349351
if err != nil {
350-
return err
352+
if !errors.Is(err, os.ErrNotExist) {
353+
return err
354+
}
355+
compressedGuestAgent, err := os.Open(guestAgentBinary + ".gz")
356+
if err != nil {
357+
return err
358+
}
359+
logrus.Debugf("Decompressing %s.gz", guestAgentBinary)
360+
guestAgent, err = gzip.NewReader(compressedGuestAgent)
361+
if err != nil {
362+
return err
363+
}
351364
}
352365
defer guestAgent.Close()
353366
layout = append(layout, iso9660util.Entry{

pkg/usrlocalsharelima/usrlocalsharelima.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package usrlocalsharelima
22

33
import (
4-
"compress/gzip"
54
"errors"
65
"fmt"
7-
"io"
86
"io/fs"
97
"os"
108
"path/filepath"
119
"runtime"
1210

1311
"github.com/lima-vm/lima/pkg/limayaml"
14-
"github.com/sirupsen/logrus"
1512
)
1613

1714
func Dir() (string, error) {
@@ -82,19 +79,3 @@ func GuestAgentBinary(ostype limayaml.OS, arch limayaml.Arch) (string, error) {
8279
}
8380
return filepath.Join(dir, "lima-guestagent."+ostype+"-"+arch), nil
8481
}
85-
86-
func Open(path string) (io.ReadCloser, error) {
87-
reader, err := os.Open(path)
88-
if errors.Is(err, os.ErrNotExist) {
89-
reader, err := os.Open(path + ".gz")
90-
if err != nil {
91-
return nil, err
92-
}
93-
logrus.Debugf("Decompressing %s.gz", path)
94-
return gzip.NewReader(reader)
95-
}
96-
if err != nil {
97-
return nil, err
98-
}
99-
return reader, nil
100-
}

0 commit comments

Comments
 (0)