Skip to content

Commit 8b2c4c7

Browse files
authored
refactor: rename VMFile to FileWrapper (#75)
1 parent 3d66efa commit 8b2c4c7

File tree

15 files changed

+60
-59
lines changed

15 files changed

+60
-59
lines changed

cmd/bauklotze/machine/start.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func start(cmd *cobra.Command, args []string) error {
7373

7474
// If the user given the report url, then overwrite the report url into mc
7575
if allFlag.ReportURL != "" {
76-
mc.ReportURL = &io.VMFile{Path: allFlag.ReportURL}
76+
mc.ReportURL = &io.FileWrapper{Path: allFlag.ReportURL}
7777
}
7878

7979
g, ctx := errgroup.WithContext(context.Background())
@@ -187,13 +187,13 @@ func cleanUp(mc *vmconfig.MachineConfig) {
187187
gvpBackendSocket, _ := mc.GVProxyNetworkBackendSocks()
188188
_ = gvpBackendSocket.Delete(true)
189189

190-
gvpBackendSocket2 := &io.VMFile{Path: fmt.Sprintf("%s-%s", gvpBackendSocket.GetPath(), "krun.sock")}
190+
gvpBackendSocket2 := &io.FileWrapper{Path: fmt.Sprintf("%s-%s", gvpBackendSocket.GetPath(), "krun.sock")}
191191
_ = gvpBackendSocket2.Delete(true)
192192

193193
podmanInHost := mc.PodmanAPISocketHost()
194194
_ = podmanInHost.Delete(true)
195195

196-
gvpPidFile := &io.VMFile{Path: mc.GvProxy.PidFile}
196+
gvpPidFile := &io.FileWrapper{Path: mc.GvProxy.PidFile}
197197
_ = gvpPidFile.Delete(true)
198198
}
199199

pkg/api/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type APIServer struct {
3131
func RestService(ctx context.Context, mc *vmconfig.MachineConfig, endPoint string) error {
3232
// Set stdin to /dev/null
3333
_ = internal.RedirectStdin()
34-
// When deleting files, wrap the path in a `&io.VMFile` so that the file is safely deleted.
34+
// When deleting files, wrap the path in a `&io.FileWrapper` so that the file is safely deleted.
3535
// The Delete(true) operation will ensure that **only files in the workspace are deleted**
36-
UDF := &io.VMFile{Path: endPoint}
36+
UDF := &io.FileWrapper{Path: endPoint}
3737
if err := UDF.Delete(true); err != nil {
3838
return fmt.Errorf("failed to delete file %q: %w", UDF.GetPath(), err)
3939
}

pkg/machine/helper/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func VirtIOFsToVFKitVirtIODevice(mounts []*volumes.Mount) ([]vfConfig.VirtioDevi
2222
return virtioDevices, nil
2323
}
2424

25-
func CreateAndResizeDisk(f *io.VMFile, newSize strongunits.GiB) error {
25+
func CreateAndResizeDisk(f *io.FileWrapper, newSize strongunits.GiB) error {
2626
if f.Exist() {
2727
if err := f.Delete(true); err != nil {
2828
return fmt.Errorf("failed to delete disk: %w", err)

pkg/machine/ignition/ignition_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func GenerateIgnScripts(mc *vmconfig.MachineConfig) error {
1717
ign := NewIgnitionBuilder(
1818
&DynamicIgnitionV3{
1919
CodeBuffer: nil,
20-
IgnFile: io.VMFile{
20+
IgnFile: io.FileWrapper{
2121
Path: ignScriptFile,
2222
},
2323
VMType: defconfig.LibKrun,
2424
Mounts: mc.Mounts,
25-
SSHIdentityPath: io.VMFile{
25+
SSHIdentityPath: io.FileWrapper{
2626
Path: mc.SSH.IdentityPath,
2727
},
2828
})

pkg/machine/ignition/ignition_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestNewIgnitionBuilder(t *testing.T) {
1717
ign := NewIgnitionBuilder(
1818
&DynamicIgnitionV3{
1919
CodeBuffer: nil,
20-
IgnFile: io.VMFile{
20+
IgnFile: io.FileWrapper{
2121
Path: filepath.Join("/tmp", "initfs", "ign.sh"),
2222
},
2323
VMType: defconfig.LibKrun,

pkg/machine/ignition/ignition_v3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
)
1919

2020
type DynamicIgnitionV3 struct {
21-
IgnFile io.VMFile
21+
IgnFile io.FileWrapper
2222
VMType defconfig.VMType
2323
Mounts []*volumes.Mount
24-
SSHIdentityPath io.VMFile
24+
SSHIdentityPath io.FileWrapper
2525
TimeZone string
2626
CodeBuffer *bytes.Buffer
2727
}

pkg/machine/io/vmfile.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,43 @@
44
package io
55

66
import (
7-
allFlag "bauklotze/pkg/machine/allflag"
87
"errors"
98
"fmt"
109
"io"
1110
"os"
1211
"path/filepath"
1312
"strings"
1413

14+
allFlag "bauklotze/pkg/machine/allflag"
15+
1516
"github.com/sirupsen/logrus"
1617

1718
"github.com/containers/common/pkg/strongunits"
1819
)
1920

20-
type VMFile struct {
21+
type FileWrapper struct {
2122
Path string `json:"path,omitempty"`
2223
}
2324

24-
// NewMachineFile is a constructor for VMFile
25-
func NewMachineFile(f string) (*VMFile, error) {
25+
// NewMachineFile is a constructor for FileWrapper
26+
func NewMachineFile(f string) (*FileWrapper, error) {
2627
if len(f) < 1 {
2728
return nil, errors.New("invalid file path, must be at least 1 character")
2829
}
2930

30-
mf := VMFile{Path: f}
31+
mf := FileWrapper{Path: f}
3132
return &mf, nil
3233
}
3334

3435
// GetPath returns the working path for a machinefile. it returns
3536
// the symlink unless one does not exist
36-
func (m *VMFile) GetPath() string {
37+
func (m *FileWrapper) GetPath() string {
3738
return m.Path
3839
}
3940

4041
// Delete dangerous removes a file from the filesystem
4142
// if safety is true, it will only remove files in the workspace
42-
func (m *VMFile) Delete(safety bool) error {
43+
func (m *FileWrapper) Delete(safety bool) error {
4344
if safety {
4445
workspace := allFlag.WorkSpace
4546
if workspace == "" {
@@ -58,17 +59,17 @@ func (m *VMFile) Delete(safety bool) error {
5859
}
5960

6061
// Read the contents of a given file and return in []bytes
61-
func (m *VMFile) Read() ([]byte, error) {
62+
func (m *FileWrapper) Read() ([]byte, error) {
6263
return os.ReadFile(m.GetPath()) //nolint:wrapcheck
6364
}
6465

65-
func (m *VMFile) Exist() bool {
66+
func (m *FileWrapper) Exist() bool {
6667
_, err := os.Stat(m.Path)
6768
return err == nil
6869
}
6970

7071
// DiscardBytesAtBegin discards the first n MB of a file
71-
func (m *VMFile) DiscardBytesAtBegin(n strongunits.MiB) error {
72+
func (m *FileWrapper) DiscardBytesAtBegin(n strongunits.MiB) error {
7273
fileInfo, err := os.Stat(m.Path)
7374
if err != nil {
7475
return fmt.Errorf("failed to get file info: %w", err)
@@ -94,15 +95,15 @@ func (m *VMFile) DiscardBytesAtBegin(n strongunits.MiB) error {
9495
}
9596

9697
// AppendToNewVMFile takes a given path and appends it to the existing vmfile path. The new
97-
// VMFile is returned
98-
func (m *VMFile) AppendToNewVMFile(additionalPath string) (*VMFile, error) {
98+
// FileWrapper is returned
99+
func (m *FileWrapper) AppendToNewVMFile(additionalPath string) (*FileWrapper, error) {
99100
if additionalPath == "" {
100101
return nil, errors.New("invalid additional path")
101102
}
102103
return NewMachineFile(filepath.Join(m.Path, additionalPath))
103104
}
104105

105-
func (m *VMFile) MakeBaseDir() error {
106+
func (m *FileWrapper) MakeBaseDir() error {
106107
err := os.MkdirAll(filepath.Dir(m.GetPath()), os.ModePerm)
107108
if err != nil {
108109
return fmt.Errorf("failed to create base dir: %w", err)

pkg/machine/shim/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Init(mp vmconfig.VMProvider) error {
108108

109109
// set ReportURL into machine configure
110110
if allFlag.ReportURL != "" {
111-
mc.ReportURL = &io.VMFile{Path: allFlag.ReportURL}
111+
mc.ReportURL = &io.FileWrapper{Path: allFlag.ReportURL}
112112
}
113113

114114
// Write the machine configure as json into mc.ConfigPath.GetPath()

pkg/machine/shim/networking.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ConductVMReadinessCheck(ctx context.Context, mc *vmconfig.MachineConfig) bo
4242
}
4343

4444
// startNetworking return podman socks in host, podman socks in guest, error
45-
func startNetworking(ctx context.Context, mc *vmconfig.MachineConfig) (*io.VMFile, *io.VMFile, error) {
45+
func startNetworking(ctx context.Context, mc *vmconfig.MachineConfig) (*io.FileWrapper, *io.FileWrapper, error) {
4646
// socksInHost($workspace/tmp/[machine]-podman-api.socks) <--> socksInGuest(podman server)
4747
socksInHost, socksInGuest, err := setupPodmanSocketsPath(mc)
4848
if err != nil {
@@ -54,5 +54,5 @@ func startNetworking(ctx context.Context, mc *vmconfig.MachineConfig) (*io.VMFil
5454
return nil, nil, fmt.Errorf("failed to start forwarder: %w", err)
5555
}
5656

57-
return &io.VMFile{Path: socksInHost}, &io.VMFile{Path: socksInGuest}, err
57+
return &io.FileWrapper{Path: socksInHost}, &io.FileWrapper{Path: socksInGuest}, err
5858
}

pkg/machine/vmconfig/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ type ResourceConfig struct {
2525
}
2626

2727
type MachineDirs struct {
28-
ConfigDir *io.VMFile `json:"ConfigDir"`
29-
DataDir *io.VMFile `json:"DataDir"`
30-
LogsDir *io.VMFile `json:"LogsDir"`
28+
ConfigDir *io.FileWrapper `json:"ConfigDir"`
29+
DataDir *io.FileWrapper `json:"DataDir"`
30+
LogsDir *io.FileWrapper `json:"LogsDir"`
3131
Hypervisor *Hypervisor `json:"Hypervisor"`
3232
NetworkProvider *NetworkProvider `json:"NetworkProvider"`
33-
SocksDir *io.VMFile `json:"SocksDir"`
33+
SocksDir *io.FileWrapper `json:"SocksDir"`
3434
}
3535

3636
type Hypervisor struct {
37-
LibsDir *io.VMFile `json:"LibsDir"`
38-
Bin *io.VMFile `json:"Bin"`
37+
LibsDir *io.FileWrapper `json:"LibsDir"`
38+
Bin *io.FileWrapper `json:"Bin"`
3939
}
4040

4141
type NetworkProvider struct {
42-
LibsDir *io.VMFile `json:"LibsDir"`
43-
Bin *io.VMFile `json:"Bin"`
42+
LibsDir *io.FileWrapper `json:"LibsDir"`
43+
Bin *io.FileWrapper `json:"Bin"`
4444
}

0 commit comments

Comments
 (0)