Skip to content

Commit

Permalink
Use custom executable path search only on unix systems
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jan 31, 2025
1 parent 234124d commit 9d87a4c
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package io.github.sgtsilvio.gradle.oci.internal

import org.apache.commons.lang3.SystemUtils
import java.io.File
import kotlin.io.path.Path
import kotlin.io.path.exists
import kotlin.io.path.isDirectory

internal fun findExecutablePath(name: String): String {
val pathEnvVar = System.getenv("PATH") ?: return name
val searchPaths = pathEnvVar.split(File.pathSeparatorChar)
for (searchPath in searchPaths) {
val path = try {
Path(searchPath, name)
} catch (ignored: IllegalArgumentException) {
continue
}
if (path.exists() && !path.isDirectory()) {
return path.toString()
if (SystemUtils.IS_OS_UNIX) {
val pathEnvVar = System.getenv("PATH") ?: return name
val searchPaths = pathEnvVar.split(File.pathSeparatorChar)
for (searchPath in searchPaths) {
val path = try {
Path(searchPath, name)
} catch (ignored: IllegalArgumentException) {
continue
}
if (path.exists() && !path.isDirectory()) {
return path.toString()
}
}
}
return name
Expand Down

0 comments on commit 9d87a4c

Please sign in to comment.