@@ -11,6 +11,7 @@ import (
11
11
"os"
12
12
"path/filepath"
13
13
"strconv"
14
+ "strings"
14
15
"syscall"
15
16
16
17
"github.com/Code-Hex/vz/v3"
@@ -356,20 +357,28 @@ func attachDisks(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfigura
356
357
return fmt .Errorf ("failed to run detect disk format %q: %q" , diskName , err )
357
358
}
358
359
if extraDiskFormat != "raw" {
360
+ if strings .Contains (extraDiskFormat , string (os .PathSeparator )) {
361
+ return fmt .Errorf (
362
+ "failed to convert disk %q to raw for vz driver because extraDiskFormat %q contains a path separator %q" ,
363
+ diskName ,
364
+ extraDiskFormat ,
365
+ os .PathSeparator ,
366
+ )
367
+ }
359
368
rawPath := fmt .Sprintf ("%s.raw" , extraDiskPath )
360
- qcow2Path := fmt .Sprintf ("%s.qcow2 " , extraDiskPath )
361
- if err = imgutil .QCOWToRaw (extraDiskPath , rawPath ); err != nil {
362
- return fmt .Errorf ("failed to convert qcow2 disk %q to raw for vz driver: %w" , diskName , err )
369
+ oldFormatPath := fmt .Sprintf ("%s.%s " , extraDiskPath , extraDiskFormat )
370
+ if err = imgutil .ConvertToRaw (extraDiskPath , rawPath ); err != nil {
371
+ return fmt .Errorf ("failed to convert %s disk %q to raw for vz driver: %w" , extraDiskFormat , diskName , err )
363
372
}
364
- if err = os .Rename (extraDiskPath , qcow2Path ); err != nil {
373
+ if err = os .Rename (extraDiskPath , oldFormatPath ); err != nil {
365
374
return fmt .Errorf ("failed to rename additional disk for vz driver: %w" , err )
366
375
}
367
376
if err = os .Rename (rawPath , extraDiskPath ); err != nil {
368
377
return fmt .Errorf ("failed to rename additional disk for vz driver: %w" , err )
369
378
}
370
- if err = os .Remove (qcow2Path ); err != nil {
379
+ if err = os .Remove (oldFormatPath ); err != nil {
371
380
logrus .Errorf ("Failed to delete unused qcow2 additional disk %q." +
372
- "Disk is no longer needed by Lima and it can be removed manually." , qcow2Path )
381
+ "Disk is no longer needed by Lima and it can be removed manually." , oldFormatPath )
373
382
}
374
383
}
375
384
0 commit comments