From 13be37ee44d48640c4bd9b39680441429d567021 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Thu, 17 Sep 2020 07:25:00 +0100 Subject: [PATCH] add support for running cygwin/msys2 based cd/iso creation tool (e.g. xorriso) --- common/step_create_cdrom.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/common/step_create_cdrom.go b/common/step_create_cdrom.go index ed035b7d3..5680052fb 100644 --- a/common/step_create_cdrom.go +++ b/common/step_create_cdrom.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "github.com/hashicorp/packer/helper/builder/localexec" @@ -167,12 +168,34 @@ var supportedCDISOCreationCommands []cdISOCreationCommand = []cdISOCreationComma }, } +func isCygwinExecutable(path string) bool { + return runtime.GOOS == "windows" && strings.Contains(path, "\\usr\\bin\\") +} + +func toCygwinPath(path string) (string, error) { + c := exec.Command("cygpath", path) + cygwinPath, err := c.Output() + return strings.TrimSpace(string(cygwinPath)), err +} + func retrieveCDISOCreationCommand(label string, source string, dest string) (*exec.Cmd, error) { for _, c := range supportedCDISOCreationCommands { path, err := exec.LookPath(c.Name) if err != nil { continue } + // if we are running a cygwin/msys2 executable we must convert the + // native win32 path to a cygwin/msys2/unix style path. + if isCygwinExecutable(path) { + source, err = toCygwinPath(source) + if err != nil { + return nil, err + } + dest, err = toCygwinPath(dest) + if err != nil { + return nil, err + } + } return c.Command(path, label, source, dest), nil } var commands = make([]string, 0, len(supportedCDISOCreationCommands))