File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
BridgeJS/Sources/TS2Skeleton Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,17 @@ import protocol Dispatch.DispatchSourceSignal
1212import class Dispatch. DispatchSource
1313
1414internal func which( _ executable: String ) throws -> URL {
15+ func checkCandidate( _ candidate: URL ) -> Bool {
16+ var isDirectory : ObjCBool = false
17+ let fileExists = FileManager . default. fileExists ( atPath: candidate. path, isDirectory: & isDirectory)
18+ return fileExists && !isDirectory. boolValue && FileManager . default. isExecutableFile ( atPath: candidate. path)
19+ }
1520 do {
1621 // Check overriding environment variable
1722 let envVariable = executable. uppercased ( ) . replacingOccurrences ( of: " - " , with: " _ " ) + " _PATH "
1823 if let path = ProcessInfo . processInfo. environment [ envVariable] {
1924 let url = URL ( fileURLWithPath: path) . appendingPathComponent ( executable)
20- if FileManager . default . isExecutableFile ( atPath : url. path ) {
25+ if checkCandidate ( url) {
2126 return url
2227 }
2328 }
@@ -31,7 +36,7 @@ internal func which(_ executable: String) throws -> URL {
3136 let paths = ProcessInfo . processInfo. environment [ " PATH " ] !. split ( separator: pathSeparator)
3237 for path in paths {
3338 let url = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( executable)
34- if FileManager . default . isExecutableFile ( atPath : url. path ) {
39+ if checkCandidate ( url) {
3540 return url
3641 }
3742 }
Original file line number Diff line number Diff line change @@ -317,12 +317,17 @@ final class DefaultPackagingSystem: PackagingSystem {
317317}
318318
319319internal func which( _ executable: String ) throws -> URL {
320+ func checkCandidate( _ candidate: URL ) -> Bool {
321+ var isDirectory : ObjCBool = false
322+ let fileExists = FileManager . default. fileExists ( atPath: candidate. path, isDirectory: & isDirectory)
323+ return fileExists && !isDirectory. boolValue && FileManager . default. isExecutableFile ( atPath: candidate. path)
324+ }
320325 do {
321326 // Check overriding environment variable
322327 let envVariable = executable. uppercased ( ) . replacingOccurrences ( of: " - " , with: " _ " ) + " _PATH "
323328 if let path = ProcessInfo . processInfo. environment [ envVariable] {
324329 let url = URL ( fileURLWithPath: path) . appendingPathComponent ( executable)
325- if FileManager . default . isExecutableFile ( atPath : url. path ) {
330+ if checkCandidate ( url) {
326331 return url
327332 }
328333 }
@@ -336,7 +341,7 @@ internal func which(_ executable: String) throws -> URL {
336341 let paths = ProcessInfo . processInfo. environment [ " PATH " ] !. split ( separator: pathSeparator)
337342 for path in paths {
338343 let url = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( executable)
339- if FileManager . default . isExecutableFile ( atPath : url. path ) {
344+ if checkCandidate ( url) {
340345 return url
341346 }
342347 }
You can’t perform that action at this time.
0 commit comments