@@ -8,37 +8,35 @@ import (
8
8
"os"
9
9
)
10
10
11
- // QemuImageUtil is the QEMU implementation of the proxyimgutil. Interface
11
+ // QemuImageUtil is the QEMU implementation of the proxyimgutil Interface.
12
12
type QemuImageUtil struct {
13
13
// Default format to use when creating disks
14
14
DefaultFormat string
15
15
}
16
16
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.
18
18
func NewQemuImageUtil () * QemuImageUtil {
19
19
return & QemuImageUtil {
20
20
DefaultFormat : "qcow2" ,
21
21
}
22
22
}
23
23
24
- // CreateDisk creates a new disk image with the specified size
24
+ // CreateDisk creates a new disk image with the specified size.
25
25
func (q * QemuImageUtil ) CreateDisk (disk string , size int ) error {
26
26
return createDisk (disk , q .DefaultFormat , size )
27
27
}
28
28
29
- // ResizeDisk resizes an existing disk image to the specified size
29
+ // ResizeDisk resizes an existing disk image to the specified size.
30
30
func (q * QemuImageUtil ) ResizeDisk (disk string , size int ) error {
31
- // Get the format of the disk
32
31
info , err := getInfo (disk )
33
32
if err != nil {
34
33
return fmt .Errorf ("failed to get info for disk %q: %w" , disk , err )
35
34
}
36
35
return resizeDisk (disk , info .Format , size )
37
36
}
38
37
39
- // ConvertToRaw converts a disk image to raw format
38
+ // ConvertToRaw converts a disk image to raw format.
40
39
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
42
40
if ! allowSourceWithBackingFile {
43
41
info , err := getInfo (source )
44
42
if err != nil {
@@ -49,12 +47,10 @@ func (q *QemuImageUtil) ConvertToRaw(source, dest string, size *int64, allowSour
49
47
}
50
48
}
51
49
52
- // Convert to raw
53
50
if err := convertToRaw (source , dest ); err != nil {
54
51
return err
55
52
}
56
53
57
- // If size is specified, resize the raw disk after conversion
58
54
if size != nil {
59
55
destInfo , err := getInfo (dest )
60
56
if err != nil {
@@ -69,20 +65,20 @@ func (q *QemuImageUtil) ConvertToRaw(source, dest string, size *int64, allowSour
69
65
return nil
70
66
}
71
67
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 {
74
70
return nil
75
71
}
76
72
77
- // QemuInfoProvider is the QEMU implementation of the proxyimgutil. InfoProvider
73
+ // QemuInfoProvider is the QEMU implementation of the proxyimgutil InfoProvider.
78
74
type QemuInfoProvider struct {}
79
75
80
- // NewQemuInfoProvider returns a new QemuInfoProvider instance
76
+ // NewQemuInfoProvider returns a new QemuInfoProvider instance.
81
77
func NewQemuInfoProvider () * QemuInfoProvider {
82
78
return & QemuInfoProvider {}
83
79
}
84
80
85
- // GetInfo retrieves information about a disk image
81
+ // GetInfo retrieves information about a disk image.
86
82
func (q * QemuInfoProvider ) GetInfo (path string ) (* Info , error ) {
87
83
qemuInfo , err := getInfo (path )
88
84
if err != nil {
@@ -92,7 +88,7 @@ func (q *QemuInfoProvider) GetInfo(path string) (*Info, error) {
92
88
return qemuInfo , nil
93
89
}
94
90
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.
96
92
func (q * QemuInfoProvider ) AcceptableAsBasedisk (info * Info ) error {
97
93
return acceptableAsBasedisk (info )
98
94
}
0 commit comments