From 637934ff2991dc81c7117d707f2677da0f46def1 Mon Sep 17 00:00:00 2001 From: akhil Date: Wed, 20 Mar 2024 14:37:49 +0530 Subject: [PATCH 1/2] fixing for mac and linux as well --- .gitignore | 3 ++- hypervisor/virtualbox/virtualbox.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8e0fd9e..092ab87 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea *.iml .vscode/ -vermin.exe \ No newline at end of file +vermin.exe +vermin \ No newline at end of file diff --git a/hypervisor/virtualbox/virtualbox.go b/hypervisor/virtualbox/virtualbox.go index 04a98c2..b4f1e5d 100644 --- a/hypervisor/virtualbox/virtualbox.go +++ b/hypervisor/virtualbox/virtualbox.go @@ -40,7 +40,6 @@ func (*virtualbox) Commit(vmName, imageName string) error { func (*virtualbox) Create(imageName, vmName string, cpus int, mem int) error { imagePath := db.GetImageFilePath(imageName) - importArgs := []string{ "import", imagePath, @@ -51,8 +50,11 @@ func (*virtualbox) Create(imageName, vmName string, cpus int, mem int) error { "--memory", strconv.Itoa(mem), } + // Wrap each argument in quotes if it contains spaces for i, arg := range importArgs { - importArgs[i] = `"` + arg + `"` + if strings.Contains(arg, " ") { + importArgs[i] = `"` + arg + `"` + } } importCmd := vboxManage(importArgs...) From aa5ffd5f681891393c076e5807155f0c9fdaec4a Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 20 Mar 2024 21:32:08 +0530 Subject: [PATCH 2/2] reverting to older code and updating the code to include quotes in just pathnames --- hypervisor/virtualbox/virtualbox.go | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/hypervisor/virtualbox/virtualbox.go b/hypervisor/virtualbox/virtualbox.go index b4f1e5d..88e78fa 100644 --- a/hypervisor/virtualbox/virtualbox.go +++ b/hypervisor/virtualbox/virtualbox.go @@ -38,27 +38,14 @@ func (*virtualbox) Commit(vmName, imageName string) error { } func (*virtualbox) Create(imageName, vmName string, cpus int, mem int) error { - - imagePath := db.GetImageFilePath(imageName) - importArgs := []string{ - "import", - imagePath, + importCmd := vboxManage( + "import", `"`+db.GetImageFilePath(imageName)+`"`, "--vsys", "0", "--vmname", vmName, - "--basefolder", db.VMsBaseDir, - "--cpus", strconv.Itoa(cpus), - "--memory", strconv.Itoa(mem), - } - - // Wrap each argument in quotes if it contains spaces - for i, arg := range importArgs { - if strings.Contains(arg, " ") { - importArgs[i] = `"` + arg + `"` - } - } - - importCmd := vboxManage(importArgs...) - + "--basefolder", `"`+db.VMsBaseDir+`"`, + "--cpus", fmt.Sprintf("%d", cpus), + "--memory", fmt.Sprintf("%d", mem), + ) if _, err := importCmd.CallWithProgress(fmt.Sprintf("Creating %s from image %s", vmName, imageName)); err != nil { return err }