99 "os"
1010 "os/exec"
1111
12+ "github.com/lima-vm/go-qcow2reader/image"
13+ "github.com/lima-vm/go-qcow2reader/image/raw"
14+
1215 "github.com/lima-vm/lima/v2/pkg/imgutil"
1316 "github.com/lima-vm/lima/v2/pkg/imgutil/nativeimgutil"
1417 "github.com/lima-vm/lima/v2/pkg/qemuimgutil"
@@ -52,16 +55,20 @@ func (p *ImageDiskManager) ResizeDisk(ctx context.Context, disk string, size int
5255 return err
5356}
5457
55- // ConvertToRaw converts a disk image to raw format.
56- func (p * ImageDiskManager ) ConvertToRaw (ctx context.Context , source , dest string , size * int64 , allowSourceWithBackingFile bool ) error {
57- err := p .qemu .ConvertToRaw (ctx , source , dest , size , allowSourceWithBackingFile )
58- if err == nil {
59- return nil
60- }
61- if errors .Is (err , exec .ErrNotFound ) {
62- return p .native .ConvertToRaw (ctx , source , dest , size , allowSourceWithBackingFile )
58+ // Convert converts a disk image to the specified format.
59+ // Currently supported formats are raw.Type and asif.Type.
60+ func (p * ImageDiskManager ) Convert (ctx context.Context , imageType image.Type , source , dest string , size * int64 , allowSourceWithBackingFile bool ) error {
61+ if imageType == raw .Type {
62+ err := p .qemu .Convert (ctx , imageType , source , dest , size , allowSourceWithBackingFile )
63+ if err == nil {
64+ return nil
65+ }
66+ if errors .Is (err , exec .ErrNotFound ) {
67+ return p .native .Convert (ctx , imageType , source , dest , size , allowSourceWithBackingFile )
68+ }
69+ return err
6370 }
64- return err
71+ return p . native . Convert ( ctx , imageType , source , dest , size , allowSourceWithBackingFile )
6572}
6673
6774func (p * ImageDiskManager ) MakeSparse (ctx context.Context , f * os.File , offset int64 ) error {
@@ -74,8 +81,3 @@ func (p *ImageDiskManager) MakeSparse(ctx context.Context, f *os.File, offset in
7481 }
7582 return err
7683}
77-
78- func (p * ImageDiskManager ) ConvertToASIF (ctx context.Context , source , dest string , size * int64 , allowSourceWithBackingFile bool ) error {
79- // ASIF conversion is only supported by the native image utility.
80- return p .native .ConvertToASIF (ctx , source , dest , size , allowSourceWithBackingFile )
81- }
0 commit comments