Merge pull request #5835 from hashicorp/fix_5767

fix file leak
pull/5648/merge
Matthew Hooker 8 years ago committed by GitHub
commit 96bbf964f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,9 +3,7 @@ package common
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
commonssh "github.com/hashicorp/packer/common/ssh"
"github.com/hashicorp/packer/communicator/ssh"
@ -23,19 +21,12 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
}
log.Println("Lookup up IP information...")
f, err := os.Open(vmxPath)
if err != nil {
return "", err
}
defer f.Close()
vmxBytes, err := ioutil.ReadAll(f)
vmxData, err := ReadVMX(vmxPath)
if err != nil {
return "", err
}
vmxData := ParseVMX(string(vmxBytes))
var ok bool
macAddress := ""
if macAddress, ok = vmxData["ethernet0.address"]; !ok || macAddress == "" {

@ -3,7 +3,6 @@ package common
import (
"context"
"fmt"
"io/ioutil"
"log"
"regexp"
"strings"
@ -26,7 +25,7 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult
ui := state.Get("ui").(packer.Ui)
vmxPath := state.Get("vmx_path").(string)
vmxContents, err := ioutil.ReadFile(vmxPath)
vmxData, err := ReadVMX(vmxPath)
if err != nil {
err := fmt.Errorf("Error reading VMX file: %s", err)
state.Put("error", err)
@ -34,8 +33,6 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult
return multistep.ActionHalt
}
vmxData := ParseVMX(string(vmxContents))
// Set this so that no dialogs ever appear from Packer.
vmxData["msg.autoanswer"] = "true"

@ -3,11 +3,9 @@ package common
import (
"context"
"fmt"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
@ -87,17 +85,9 @@ func (s *StepConfigureVNC) Run(_ context.Context, state multistep.StateBag) mult
ui := state.Get("ui").(packer.Ui)
vmxPath := state.Get("vmx_path").(string)
f, err := os.Open(vmxPath)
vmxData, err := ReadVMX(vmxPath)
if err != nil {
err := fmt.Errorf("Error reading VMX data: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
vmxBytes, err := ioutil.ReadAll(f)
if err != nil {
err := fmt.Errorf("Error reading VMX data: %s", err)
err := fmt.Errorf("Error reading VMX file: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
@ -121,7 +111,6 @@ func (s *StepConfigureVNC) Run(_ context.Context, state multistep.StateBag) mult
log.Printf("Found available VNC port: %d", vncPort)
vmxData := ParseVMX(string(vmxBytes))
vncFinder.UpdateVMX(vncBindAddress, vncPassword, vncPort, vmxData)
if err := WriteVMX(vmxPath, vmxData); err != nil {

Loading…
Cancel
Save