Skip to content

Commit

Permalink
Extract out posssible exec path functionality from getExecPath to get…
Browse files Browse the repository at this point in the history
…PossibleExecPaths. Added detection for .bat aliases on windows.
  • Loading branch information
balupton committed Jun 28, 2013
1 parent fadef4b commit 63c8e34
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/lib/safeps.coffee
Expand Up @@ -358,14 +358,30 @@ safeps =
# Prepare
pathUtil = require('path')

# Prepare
possibleExecPaths = [process.cwd()].concat(safeps.getEnvironmentPaths())
# Fetch
standardExecPaths = [process.cwd()].concat(safeps.getEnvironmentPaths())

# Get the possible exec paths
if execName
possibleExecPaths = possibleExecPaths.map (path) ->
standardExecPaths = standardExecPaths.map (path) ->
return pathUtil.join(path, execName)

# Return
return standardExecPaths

# Get Possible Exec Paths
getPossibleExecPaths: (execName) ->
# Fetch available paths
if isWindows and execName.indexOf('.') is -1
# we are for windows add the paths for .exe as well
standardExecPaths = safeps.getStandardExecPaths(execName)
possibleExecPaths = []
for standardExecPath in standardExecPaths
possibleExecPaths.push(standardExecPath, standardExecPath+'.exe', standardExecPath+'.bat')
else
# we are normal, try the paths
possibleExecPaths = safeps.getStandardExecPaths(execName)

# Return
return possibleExecPaths

Expand All @@ -390,13 +406,8 @@ safeps =
if safeps[getExecMethodName]?
safeps[getExecMethodName](next)
else
# Fetch available paths
if isWindows and execName.indexOf('.') is -1
# we are for windows add the paths for .exe as well
possibleExecPaths = safeps.getStandardExecPaths(execName+'.exe').concat(safeps.getStandardExecPaths(execName))
else
# we are normal, try the paths
possibleExecPaths = safeps.getStandardExecPaths(execName)
# Fetch possible exec paths
possibleExecPaths = safeps.getPossibleExecPaths(execName)

# Forward onto determineExecPath
# Which will determine which path it is out of the possible paths
Expand Down

0 comments on commit 63c8e34

Please sign in to comment.