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
12
12
import class Dispatch. DispatchSource
13
13
14
14
internal 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
+ }
15
20
do {
16
21
// Check overriding environment variable
17
22
let envVariable = executable. uppercased ( ) . replacingOccurrences ( of: " - " , with: " _ " ) + " _PATH "
18
23
if let path = ProcessInfo . processInfo. environment [ envVariable] {
19
24
let url = URL ( fileURLWithPath: path) . appendingPathComponent ( executable)
20
- if FileManager . default . isExecutableFile ( atPath : url. path ) {
25
+ if checkCandidate ( url) {
21
26
return url
22
27
}
23
28
}
@@ -31,7 +36,7 @@ internal func which(_ executable: String) throws -> URL {
31
36
let paths = ProcessInfo . processInfo. environment [ " PATH " ] !. split ( separator: pathSeparator)
32
37
for path in paths {
33
38
let url = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( executable)
34
- if FileManager . default . isExecutableFile ( atPath : url. path ) {
39
+ if checkCandidate ( url) {
35
40
return url
36
41
}
37
42
}
Original file line number Diff line number Diff line change @@ -317,12 +317,17 @@ final class DefaultPackagingSystem: PackagingSystem {
317
317
}
318
318
319
319
internal 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
+ }
320
325
do {
321
326
// Check overriding environment variable
322
327
let envVariable = executable. uppercased ( ) . replacingOccurrences ( of: " - " , with: " _ " ) + " _PATH "
323
328
if let path = ProcessInfo . processInfo. environment [ envVariable] {
324
329
let url = URL ( fileURLWithPath: path) . appendingPathComponent ( executable)
325
- if FileManager . default . isExecutableFile ( atPath : url. path ) {
330
+ if checkCandidate ( url) {
326
331
return url
327
332
}
328
333
}
@@ -336,7 +341,7 @@ internal func which(_ executable: String) throws -> URL {
336
341
let paths = ProcessInfo . processInfo. environment [ " PATH " ] !. split ( separator: pathSeparator)
337
342
for path in paths {
338
343
let url = URL ( fileURLWithPath: String ( path) ) . appendingPathComponent ( executable)
339
- if FileManager . default . isExecutableFile ( atPath : url. path ) {
344
+ if checkCandidate ( url) {
340
345
return url
341
346
}
342
347
}
You can’t perform that action at this time.
0 commit comments