@@ -103,35 +103,31 @@ type InfoFormatSpecificDataVmdkExtent struct {
103
103
}
104
104
105
105
func convertToRaw (source , dest string ) error {
106
- // If source == dest, we need to use a temporary file to avoid file locking issues
107
- if source == dest {
108
- // Get info to check if it's already raw format
109
- info , err := getInfo (source )
110
- if err != nil {
111
- return fmt .Errorf ("failed to get info for source disk %q: %w" , source , err )
112
- }
113
- // If already raw, no conversion needed
114
- if info .Format == "raw" {
115
- return nil
116
- }
106
+ if source != dest {
107
+ return execQemuImgConvert (source , dest )
108
+ }
117
109
118
- // Create temporary file for conversion
119
- tempFile := dest + ".lima-qemu-convert.tmp"
120
- defer os .Remove (tempFile ) // Clean up temp file
110
+ // If source == dest, we need to use a temporary file to avoid file locking issues
111
+
112
+ info , err := getInfo (source )
113
+ if err != nil {
114
+ return fmt .Errorf ("failed to get info for source disk %q: %w" , source , err )
115
+ }
116
+ if info .Format == "raw" {
117
+ return nil
118
+ }
121
119
122
- // Convert to temp file first
123
- if err := convertToRawHelper (source , tempFile ); err != nil {
124
- return err
125
- }
120
+ tempFile := dest + ".lima-qemu-convert.tmp"
121
+ defer os .Remove (tempFile )
126
122
127
- // Replace original with converted file
128
- return os . Rename ( tempFile , dest )
123
+ if err := execQemuImgConvert ( source , tempFile ); err != nil {
124
+ return err
129
125
}
130
126
131
- return convertToRawHelper ( source , dest )
127
+ return os . Rename ( tempFile , dest )
132
128
}
133
129
134
- func convertToRawHelper (source , dest string ) error {
130
+ func execQemuImgConvert (source , dest string ) error {
135
131
var stdout , stderr bytes.Buffer
136
132
cmd := exec .Command ("qemu-img" , "convert" , "-O" , "raw" , source , dest )
137
133
cmd .Stdout = & stdout
0 commit comments