Merge pull request #6481 from hashicorp/fix_6476
don't try to determine file or folder with winrm communicator; not al…
This commit is contained in:
commit
9432067449
|
@ -124,24 +124,13 @@ func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) {
|
|||
// Upload implementation of communicator.Communicator interface
|
||||
func (c *Communicator) Upload(path string, input io.Reader, fi *os.FileInfo) error {
|
||||
wcp, err := c.newCopyClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Was unable to create winrm client: %s", err)
|
||||
}
|
||||
client, err := c.newWinRMClient()
|
||||
stdout, _, _, err := client.RunWithString(fmt.Sprintf("powershell -Command \"(Get-Item %s) -is [System.IO.DirectoryInfo]\"", path), "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't determine whether destination was a folder or file: %s", err)
|
||||
if strings.HasSuffix(path, `\`) {
|
||||
// path is a directory
|
||||
path += filepath.Base((*fi).Name())
|
||||
}
|
||||
if strings.Contains(stdout, "True") {
|
||||
// The path exists and is a directory.
|
||||
// Upload file into the directory instead of overwriting.
|
||||
path = filepath.Join(path, filepath.Base((*fi).Name()))
|
||||
}
|
||||
|
||||
log.Printf("Uploading file to '%s'", path)
|
||||
return wcp.Write(path, input)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue