Skip to content

Commit

Permalink
fix: relative paths
Browse files Browse the repository at this point in the history
This modification ensures that both `isoPath` is an absolute path.

Ref: #25

Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
  • Loading branch information
tenthirtyam committed Sep 7, 2024
1 parent 6d0b1ec commit 1c9a3d8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions builder/vmware/iso/step_create_vmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,24 @@ type stepCreateVMX struct {
}

/* regular steps */

func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
isoPath := state.Get("iso_path").(string)
ui := state.Get("ui").(packersdk.Ui)

// Convert the iso_path into a path relative to the .vmx file if possible
if relativeIsoPath, err := filepath.Rel(config.VMXTemplatePath, filepath.FromSlash(isoPath)); err == nil {
isoPath = relativeIsoPath
// Ensure ISO path is absolute.
absISOPath, err := filepath.Abs(isoPath)
if err != nil {
err := fmt.Errorf("error making ISO path absolute: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

// Use the absolute ISO path directly.
isoPath = absISOPath

ui.Say("Generating the .vmx file...")

vmxTemplate := DefaultVMXTemplate
Expand Down Expand Up @@ -108,12 +116,12 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
diskAndCDConfigData := common.DefaultDiskAndCDROMTypes(config.DiskAdapterType, config.CdromAdapterType)
ictx := config.ctx

// Mount extra vmdks we created earlier.
// Mount extra VMDKs we created earlier.
if len(config.AdditionalDiskSize) > 0 {

incrementer := 1

// Extra vmdks after Primary disk and CDROM
// Extra VMDKs after primary disk and CDROM.
unitSkip := 2

// If the CDROM is on a different bus we only have to skip the primary disk's unit.
Expand All @@ -122,7 +130,7 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
}

for i := range config.AdditionalDiskSize {
// slot 7 is special and reserved, so we need to skip that index.
// Slot 7 is special and reserved, so we need to skip that index.
if i+1 == 7 {
incrementer = 2
unitSkip += 1
Expand Down

0 comments on commit 1c9a3d8

Please sign in to comment.