44package io
55
66import (
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 )
0 commit comments