packer-community / winrmcp

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

Remove single quotes from destination paths that include spaces #14

Closed kopaka closed 8 years ago

kopaka commented 8 years ago

When toPath contains one or more spaces, it is wrapped in single quotes. If toPath also begins with a volume identifier (e.g. C:), the opening single quote offsets the colon (:) by one position in the string. This results in a NotSupportedException exception being thrown during the call to GetFullPath().

The solution is to always trim single quotes from toPath before the call to GetFullPath() is made.

dylanmei commented 8 years ago

Hello. I'm unclear where the single quotes are coming from. If they're coming from the command-line, how do you feel about trimming sooner (main, or doCopy for example) and using %q in the script formatting?

https://play.golang.org/p/J8oqAmbgh_

We've not got a dedicated place to do path cleansing, but I imagine it would be good keep it out of the PowerShell.

kopaka commented 8 years ago

The single quotes come from a call to winPath(), in path.go. winPath() is invoked in each call to doCopy(). For example: doCopy(fs.client, fs.config, src, winPath(toPath)).

The single quotes do not appear to cause an issue anywhere in the code, except for GetFullPath(). Consequently, it is probably acceptable to 'clean' the path only immediately before the call to GetFullPath().

That said, I do not see any issue with your implementation, and so cleaning the path in doCopy() itself should be fine. The key is that the single quotes are removed before the call to GetFullPath(). How (or even when) that is accomplished is likely immaterial.

dylanmei commented 8 years ago

Thanks for taking the time to highlight the problem. I've implemented my idea in a branch: 4f3734d1ca91247c231348ae054189330422d1cc.

But I'm not in a position to test it right now. Since it's more broad and risky than this PR, I'm gratefully accepting it now. Cheers.

kopaka commented 8 years ago

Thanks, @dylanmei. Happy to have helped! :)