packer-community / winrmcp

Copy files to a remote host using WinRM
MIT License
59 stars 31 forks source link

restoreContent() hangs when toPath is directory without trailing "\" #32

Closed SwampDragons closed 6 years ago

SwampDragons commented 6 years ago

The error described in https://github.com/hashicorp/packer/issues/6738 occurs because restoreContent() in cp.go hangs indefinitely if toPath is a directory that does not end with "\" -- for example, toPath provided as "destination": "C:\\Windows\\Temp" in the Packer config rather than "destination": "C:\\Windows\\Temp\\"

This can be solved one of two ways. Either, we can add a test to restoreContent's powershell script, which would force a failure that Packer can catch and provide direction on:

        if (Test-Path -Path $dest_file_path -PathType container) {
            Exit 1
        }

or, we can add a test which will append "\" to a directory if it isn't already there, which would be a bit more complex. I'm happy doing either but I'd like to implement one of these options. Which do you think would be better?