Add ability to move files on remote system
Fix salt-masterless to use generic MovePath
This commit is contained in:
parent
857e5d04d3
commit
aee67d3933
|
@ -14,6 +14,7 @@ type guestOSTypeCommand struct {
|
|||
mkdir string
|
||||
removeDir string
|
||||
statPath string
|
||||
mvPath string
|
||||
}
|
||||
|
||||
var guestOSTypeCommands = map[string]guestOSTypeCommand{
|
||||
|
@ -22,12 +23,14 @@ var guestOSTypeCommands = map[string]guestOSTypeCommand{
|
|||
mkdir: "mkdir -p '%s'",
|
||||
removeDir: "rm -rf '%s'",
|
||||
statPath: "stat '%s'",
|
||||
mv: "mv '%s' '%s'",
|
||||
},
|
||||
WindowsOSType: {
|
||||
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\"",
|
||||
statPath: "powershell.exe -Commond \"test-path %s\"",
|
||||
statPath: "powershell.exe -Command \"test-path %s\"",
|
||||
mv: "powershell.exe -Command \"mv %s %s\"",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -71,6 +74,10 @@ func (g *GuestCommands) StatPath(path string) string {
|
|||
return g.sudo(fmt.Sprintf(g.commands().statPath, g.escapePath(path)))
|
||||
}
|
||||
|
||||
func (g *GuestCommands) MovePath(srcPath string, dstPath) string {
|
||||
return g.sudo(fmt.Sprintf(g.commands().mv, g.escapePath(srcPath), g.escapePath(dstPath)))
|
||||
}
|
||||
|
||||
func (g *GuestCommands) sudo(cmd string) string {
|
||||
if g.GuestOSType == UnixOSType && g.Sudo {
|
||||
return "sudo " + cmd
|
||||
|
|
|
@ -412,7 +412,9 @@ func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst, sr
|
|||
|
||||
func (p *Provisioner) moveFile(ui packer.Ui, comm packer.Communicator, dst, src string) error {
|
||||
ui.Message(fmt.Sprintf("Moving %s to %s", src, dst))
|
||||
cmd := &packer.RemoteCmd{Command: fmt.Sprintf(p.sudo("mv %s %s"), src, dst)}
|
||||
cmd := &packer.RemoteCmd{
|
||||
Command: p.guestCommands.MovePath(src, dst),
|
||||
}
|
||||
if err := cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus)
|
||||
|
|
Loading…
Reference in New Issue