Skip to content

Commit

Permalink
More fix-ups upon clarity and correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Mar 16, 2022
1 parent 6f0bbe0 commit 8a33393
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ public final class Process {
)
var searchPaths: [AbsolutePath] = []
#if os(Windows)
// NOTE: `CreateProcess` the Windows system API always searchs System and Windows directories first.
// See https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#parameters
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
// The 32-bit Windows system directory
if GetSystemDirectoryW(&buffer, .init(buffer.count)) > 0 {
Expand Down
11 changes: 5 additions & 6 deletions Sources/TSCBasic/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ public func lookupExecutablePath(
return nil
}
#if os(Windows)
let isPath = value.contains(":") || value.contains("\\") || value.contains("/")
let isFileName = !value.contains(":") && !value.contains("\\") && !value.contains("/")
#else
let isPath = value.contains("/")
let isFileName = !value.contains("/")
#endif

var paths: [AbsolutePath] = []
Expand All @@ -241,12 +241,11 @@ public func lookupExecutablePath(
paths.append(absPath)
}

// Ensure the value is not a path.
if !isPath {
// Try to locate in search paths.
if isFileName {
// Try to locate file in search paths.
paths.append(contentsOf: searchPaths.map({ $0.appending(component: value) }))
#if os(Windows)
if !value.contains(".") {
if !value.hasSuffix(".") {
paths.append(contentsOf: searchPaths.map({ $0.appending(component: value + executableFileSuffix) }))
}
#endif
Expand Down

0 comments on commit 8a33393

Please sign in to comment.