diff --git a/provisioner/guest_commands.go b/provisioner/guest_commands.go index 1d2d1597f..47edb1768 100644 --- a/provisioner/guest_commands.go +++ b/provisioner/guest_commands.go @@ -29,7 +29,7 @@ var guestOSTypeCommands = map[string]guestOSTypeCommand{ chmod: "echo 'skipping chmod %s %s'", // no-op mkdir: "powershell.exe -Command \"New-Item -ItemType directory -Force -ErrorAction SilentlyContinue -Path %s\"", removeDir: "powershell.exe -Command \"rm %s -recurse -force -ErrorAction SilentlyContinue\"", - statPath: "powershell.exe -Command \"test-path %s\"", + statPath: "powershell.exe -Command { if (test-path %s) { exit 0 } else { exit 1 } }", mv: "powershell.exe -Command \"mv %s %s\"", }, } diff --git a/provisioner/salt-masterless/provisioner.go b/provisioner/salt-masterless/provisioner.go index 53eb59aaa..f1ae1fe84 100644 --- a/provisioner/salt-masterless/provisioner.go +++ b/provisioner/salt-masterless/provisioner.go @@ -302,8 +302,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { dst = p.guestOSTypeConfig.stateRoot } - if err = p.removeDir(ui, comm, dst); err != nil { - return fmt.Errorf("Unable to clear salt tree: %s", err) + if err = p.statPath(ui, comm, dst); err != nil { + if err = p.removeDir(ui, comm, dst); err != nil { + return fmt.Errorf("Unable to clear salt tree: %s", err) + } } if err = p.moveFile(ui, comm, dst, src); err != nil { @@ -326,9 +328,10 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { dst = p.guestOSTypeConfig.pillarRoot } - // only remove path if it exists or windows throws a fit - if err = p.removeDir(ui, comm, dst); err != nil { - return fmt.Errorf("Unable to clear pillar root: %s", err) + if err = p.statPath(ui, comm, dst); err != nil { + if err = p.removeDir(ui, comm, dst); err != nil { + return fmt.Errorf("Unable to clear pillar root: %s", err) + } } if err = p.moveFile(ui, comm, dst, src); err != nil {