Skip to content

Commit 6bc9e97

Browse files
committed
refactor: remove old qemuimgutil and nativeimgutil packages
Signed-off-by: Horiodino <[email protected]> fixed golangci-lint errs Signed-off-by: Horiodino <[email protected]>
1 parent ab9fd04 commit 6bc9e97

File tree

9 files changed

+30
-726
lines changed

9 files changed

+30
-726
lines changed

pkg/imgutil/nativeimgutil/interface.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ import (
99
imgutil "github.com/lima-vm/lima/pkg/imgutil/qemuimgutil"
1010
)
1111

12-
// NativeImageUtil is the native implementation of the proxyimgutil.Interface
12+
// NativeImageUtil is the native implementation of the proxyimgutil Interface.
1313
type NativeImageUtil struct{}
1414

15-
// NewNativeImageUtil returns a new NativeImageUtil instance
15+
// NewNativeImageUtil returns a new NativeImageUtil instance.
1616
func NewNativeImageUtil() *NativeImageUtil {
1717
return &NativeImageUtil{}
1818
}
1919

20-
// CreateDisk creates a new raw disk image with the specified size
20+
// CreateDisk creates a new raw disk image with the specified size.
2121
func (n *NativeImageUtil) CreateDisk(disk string, size int) error {
2222
return createRawDisk(disk, size)
2323
}
2424

25-
// ResizeDisk resizes an existing raw disk image to the specified size
25+
// ResizeDisk resizes an existing raw disk image to the specified size.
2626
func (n *NativeImageUtil) ResizeDisk(disk string, size int) error {
2727
return resizeRawDisk(disk, size)
2828
}
2929

30-
// ConvertToRaw converts a disk image to raw format
30+
// ConvertToRaw converts a disk image to raw format.
3131
func (n *NativeImageUtil) ConvertToRaw(source, dest string, size *int64, allowSourceWithBackingFile bool) error {
3232
return convertToRaw(source, dest, size, allowSourceWithBackingFile)
3333
}
@@ -36,23 +36,22 @@ func (n *NativeImageUtil) MakeSparse(f *os.File, offset int64) error {
3636
return makeSparse(f, offset)
3737
}
3838

39-
// NativeInfoProvider is the native implementation of the proxyimgutil.InfoProvider
39+
// NativeInfoProvider is the native implementation of the proxyimgutil.InfoProvider.
4040
type NativeInfoProvider struct{}
4141

42-
// NewNativeInfoProvider returns a new NativeInfoProvider instance
42+
// NewNativeInfoProvider returns a new NativeInfoProvider instance.
4343
func NewNativeInfoProvider() *NativeInfoProvider {
4444
return &NativeInfoProvider{}
4545
}
4646

47-
// Just a placeholder for the interface
4847
// GetInfo retrieves information about a disk image
49-
// This is a stub implementation as the native package doesn't provide this functionality
50-
func (n *NativeInfoProvider) GetInfo(path string) (*imgutil.Info, error) {
48+
// This is a stub implementation as the native package doesn't provide this functionality.
49+
func (n *NativeInfoProvider) GetInfo(_ string) (*imgutil.Info, error) {
5150
return nil, nil
5251
}
5352

5453
// AcceptableAsBasedisk checks if a disk image is acceptable as a base disk
55-
// This is a stub implementation as the native package doesn't provide this functionality
56-
func (n *NativeInfoProvider) AcceptableAsBasedisk(info *imgutil.Info) error {
54+
// This is a stub implementation as the native package doesn't provide this functionality.
55+
func (n *NativeInfoProvider) AcceptableAsBasedisk(_ *imgutil.Info) error {
5756
return nil
5857
}

pkg/imgutil/proxyimgutil/interface.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ import (
99
imgutil "github.com/lima-vm/lima/pkg/imgutil/qemuimgutil"
1010
)
1111

12-
// Interface defines the common operations for disk image utilities
12+
// Interface defines the common operations for disk image utilities.
1313
type Interface interface {
14-
// CreateDisk creates a new disk image with the specified size
14+
// CreateDisk creates a new disk image with the specified size.
1515
CreateDisk(disk string, size int) error
1616

17-
// ResizeDisk resizes an existing disk image to the specified size
17+
// ResizeDisk resizes an existing disk image to the specified size.
1818
ResizeDisk(disk string, size int) error
1919

20-
// ConvertToRaw converts a disk image to raw format
20+
// ConvertToRaw converts a disk image to raw format.
2121
ConvertToRaw(source, dest string, size *int64, allowSourceWithBackingFile bool) error
2222

23-
// MakeSparse makes a file sparse, starting from the specified offset
23+
// MakeSparse makes a file sparse, starting from the specified offset.
2424
MakeSparse(f *os.File, offset int64) error
2525
}
2626

27-
// InfoProvider defines the interface for obtaining disk image information
27+
// InfoProvider defines the interface for obtaining disk image information.
2828
type InfoProvider interface {
2929
// GetInfo retrieves information about a disk image
3030
GetInfo(path string) (*imgutil.Info, error)

pkg/imgutil/proxyimgutil/proxyimgutil.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88

99
"github.com/lima-vm/lima/pkg/imgutil/nativeimgutil"
10+
"github.com/lima-vm/lima/pkg/imgutil/qemuimgutil"
1011
)
1112

1213
// NewProxyImageUtil returns a proxy implementation for raw and qcow2 image formats.
@@ -15,7 +16,7 @@ func NewProxyImageUtil(format string) (Interface, InfoProvider, error) {
1516
case "raw":
1617
return nativeimgutil.NewNativeImageUtil(), nativeimgutil.NewNativeInfoProvider(), nil
1718
case "qcow2":
18-
return nativeimgutil.NewNativeImageUtil(), nativeimgutil.NewNativeInfoProvider(), nil
19+
return qemuimgutil.NewQemuImageUtil(), qemuimgutil.NewQemuInfoProvider(), nil
1920
default:
2021
return nil, nil, fmt.Errorf("unsupported image format: %s", format)
2122
}

pkg/imgutil/qemuimgutil/interface.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,35 @@ import (
88
"os"
99
)
1010

11-
// QemuImageUtil is the QEMU implementation of the proxyimgutil.Interface
11+
// QemuImageUtil is the QEMU implementation of the proxyimgutil Interface.
1212
type QemuImageUtil struct {
1313
// Default format to use when creating disks
1414
DefaultFormat string
1515
}
1616

17-
// NewQemuImageUtil returns a new QemuImageUtil instance with "qcow2" as the default format
17+
// NewQemuImageUtil returns a new QemuImageUtil instance with "qcow2" as the default format.
1818
func NewQemuImageUtil() *QemuImageUtil {
1919
return &QemuImageUtil{
2020
DefaultFormat: "qcow2",
2121
}
2222
}
2323

24-
// CreateDisk creates a new disk image with the specified size
24+
// CreateDisk creates a new disk image with the specified size.
2525
func (q *QemuImageUtil) CreateDisk(disk string, size int) error {
2626
return createDisk(disk, q.DefaultFormat, size)
2727
}
2828

29-
// ResizeDisk resizes an existing disk image to the specified size
29+
// ResizeDisk resizes an existing disk image to the specified size.
3030
func (q *QemuImageUtil) ResizeDisk(disk string, size int) error {
31-
// Get the format of the disk
3231
info, err := getInfo(disk)
3332
if err != nil {
3433
return fmt.Errorf("failed to get info for disk %q: %w", disk, err)
3534
}
3635
return resizeDisk(disk, info.Format, size)
3736
}
3837

39-
// ConvertToRaw converts a disk image to raw format
38+
// ConvertToRaw converts a disk image to raw format.
4039
func (q *QemuImageUtil) ConvertToRaw(source, dest string, size *int64, allowSourceWithBackingFile bool) error {
41-
// Check if source has a backing file and we don't allow it
4240
if !allowSourceWithBackingFile {
4341
info, err := getInfo(source)
4442
if err != nil {
@@ -49,12 +47,10 @@ func (q *QemuImageUtil) ConvertToRaw(source, dest string, size *int64, allowSour
4947
}
5048
}
5149

52-
// Convert to raw
5350
if err := convertToRaw(source, dest); err != nil {
5451
return err
5552
}
5653

57-
// If size is specified, resize the raw disk after conversion
5854
if size != nil {
5955
destInfo, err := getInfo(dest)
6056
if err != nil {
@@ -69,20 +65,20 @@ func (q *QemuImageUtil) ConvertToRaw(source, dest string, size *int64, allowSour
6965
return nil
7066
}
7167

72-
func (q *QemuImageUtil) MakeSparse(f *os.File, offset int64) error {
73-
// Just a placeholder for the interface
68+
// MakeSparse is a stub implementation as the native package doesn't provide this functionality.
69+
func (q *QemuImageUtil) MakeSparse(_ *os.File, _ int64) error {
7470
return nil
7571
}
7672

77-
// QemuInfoProvider is the QEMU implementation of the proxyimgutil.InfoProvider
73+
// QemuInfoProvider is the QEMU implementation of the proxyimgutil InfoProvider.
7874
type QemuInfoProvider struct{}
7975

80-
// NewQemuInfoProvider returns a new QemuInfoProvider instance
76+
// NewQemuInfoProvider returns a new QemuInfoProvider instance.
8177
func NewQemuInfoProvider() *QemuInfoProvider {
8278
return &QemuInfoProvider{}
8379
}
8480

85-
// GetInfo retrieves information about a disk image
81+
// GetInfo retrieves information about a disk image.
8682
func (q *QemuInfoProvider) GetInfo(path string) (*Info, error) {
8783
qemuInfo, err := getInfo(path)
8884
if err != nil {
@@ -92,7 +88,7 @@ func (q *QemuInfoProvider) GetInfo(path string) (*Info, error) {
9288
return qemuInfo, nil
9389
}
9490

95-
// AcceptableAsBasedisk checks if a disk image is acceptable as a base disk
91+
// AcceptableAsBasedisk checks if a disk image is acceptable as a base disk.
9692
func (q *QemuInfoProvider) AcceptableAsBasedisk(info *Info) error {
9793
return acceptableAsBasedisk(info)
9894
}

pkg/nativeimgutil/fuzz_test.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkg/nativeimgutil/nativeimgutil.go

Lines changed: 0 additions & 170 deletions
This file was deleted.

0 commit comments

Comments
 (0)