Merge pull request #5410 from hashicorp/fix_4891

fun with wait groups; prevents hanging
This commit is contained in:
SwampDragons 2017-09-29 15:11:26 -07:00 committed by GitHub
commit 732e884105
2 changed files with 22 additions and 5 deletions

View File

@ -176,13 +176,30 @@ func cleanupContent(client *winrm.Client, filePath string) error {
}
defer shell.Close()
cmd, err := shell.Execute("powershell", "Remove-Item", filePath, "-ErrorAction SilentlyContinue")
script := fmt.Sprintf(`Remove-Item %s -ErrorAction SilentlyContinue`, filePath)
cmd, err := shell.Execute(winrm.Powershell(script))
if err != nil {
return err
}
defer cmd.Close()
var wg sync.WaitGroup
copyFunc := func(w io.Writer, r io.Reader) {
defer wg.Done()
io.Copy(w, r)
}
wg.Add(2)
go copyFunc(os.Stdout, cmd.Stdout)
go copyFunc(os.Stderr, cmd.Stderr)
cmd.Wait()
cmd.Close()
wg.Wait()
if cmd.ExitCode() != 0 {
return fmt.Errorf("cleanup operation returned code=%d", cmd.ExitCode())
}
return nil
}

6
vendor/vendor.json vendored
View File

@ -959,10 +959,10 @@
"revision": "179d4d0c4d8d407a32af483c2354df1d2c91e6c3"
},
{
"checksumSHA1": "iApv8tX8vuAvzyY6VkOvW+IzJF8=",
"checksumSHA1": "XXmfaQ8fEupEgaGd6PptrLnrE54=",
"path": "github.com/packer-community/winrmcp/winrmcp",
"revision": "078cc0a785c9da54158c0775f06f505fc1e867f8",
"revisionTime": "2017-06-07T14:21:56Z"
"revision": "e1b7d6e6b1b1a27984270784190f1d06ad91888b",
"revisionTime": "2017-09-29T21:51:32Z"
},
{
"checksumSHA1": "oaXvjFg802gS/wx1bx2gAQwa7XQ=",