cake-build/resources

PowerShell bootstrapper fails when file on Path

Gudahtt opened this issue · 2 comments

I've discovered that the PowerShell bootstrapper fails when the $PATH environment variable contains a file, rather than a directory. That is, if it contains a file that happens to not be nuget.exe.

To reproduce: put any binary that isn't nuget.exe on the path, and run the bootstrapper. Ensure that nuget.exe is not present in the tools directory, to force the bootstrapper to find it.

When trying to find nuget.exe, it searches through the $PATH, and doesn't account for entries that may not be directories. It accepts any files it finds as being nuget.exe, then throws an error when it tries to execute it. This leaves your PowerShell session in the tools directory.

I'm pretty sure the $PATH environment variable is only supposed to contain directories, but... nothing stops you from adding a file. This is a fairly easy thing to fix anyway, so it couldn't hurt to be more robust in this case.

I'll put up a PR for the potential fix that I thought of.

Indeed an edge case path should by spec only contain directories. Yet it's just a string.