salt.utils.path.which() on the windows platform can return a non-executable file if a file without an extension already exists (breaks npm module on windows) #51784
Labels
Bug
broken, incorrect, or confusing behavior
P2
Priority 2
severity-low
4th level, cosemtic problems, work around exists
Milestone
Description of Issue/Question
Okay...this is getting pretty fucking outrageous. This condition can happen in numerous other places, but I encountered it specifically when installing nodejs via chocolatey and then trying to use the npm modules in salt. The issue is that in order to detect the existence of npm, salt will use
salt.utils.path.which()
to locate thenpm
binary.The
salt.utils.path.which()
function mixes up the semantics what's considered executable on Windows with what's considered executable on Posix. This mix up occurs when a script with the exact name that is being searched for exists despite the filename not ending with the correct extension. Specifically if there's two scripts..one of which is "blah.cmd" and another which is "blah", salt will return to the path to "blah" instead of "blah.cmd".This situation results in the script w/o the extension being given priority. i.e. The node.js installer bundles two scripts in your PATH one of which is a bourne-script named
npm
, and another cmd-script namednpm.cmd
. Due to the existence of the first one,salt.util.path.which()
returns the path to this instead ofnpm.cmd
which is the correct command to run since it has an extension inPATHEXT
.In the node.js example which calls
salt.utils.path.which('npm')
, it'll log the following error due tonpm
not being being executable from the windows shell.Setup
On the Windows platform, drop two files named
test
andtest.cmd
in the search PATH. If you want to execute something, put some cmd-script that redirects some text into a logfile or something in either.Steps to Reproduce Issue
After getting two files in your path, simply call
salt.utils.path.which()
and it will return the path to thetest
file instead of the one with the correct extension. As mentioned, this is wrong astest
cannot be executed from the command shell due to its extension not existing in PATHEXT.To prove that you can't execute the first script, try passing it to os.system or something.
Versions Report
The text was updated successfully, but these errors were encountered: