Fixed stating of files on windows

added directory existence check to salt provisioner before directory clean up
This commit is contained in:
Dave Sanderson 2017-12-13 10:20:27 -07:00
parent 57770de36f
commit 284b069003
2 changed files with 9 additions and 6 deletions

View File

@ -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\"",
},
}

View File

@ -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 {