From 91217d9f49954e03fff991f23de5bd52804396b7 Mon Sep 17 00:00:00 2001 From: Vadim Briliantov Date: Thu, 16 Jun 2022 21:35:58 +0200 Subject: [PATCH] Respect HOME variable --- .../kotlin/io/ktor/generator/cli/utils/FileSystemUtils.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/macosX64Main/kotlin/io/ktor/generator/cli/utils/FileSystemUtils.kt b/src/macosX64Main/kotlin/io/ktor/generator/cli/utils/FileSystemUtils.kt index 9aa85e4..5c240df 100644 --- a/src/macosX64Main/kotlin/io/ktor/generator/cli/utils/FileSystemUtils.kt +++ b/src/macosX64Main/kotlin/io/ktor/generator/cli/utils/FileSystemUtils.kt @@ -1,5 +1,7 @@ package io.ktor.generator.cli.utils +import io.ktor.generator.cli.installer.* +import io.ktor.generator.cli.installer.getEnv import kotlinx.cinterop.ByteVar import kotlinx.cinterop.CPointer import kotlinx.cinterop.pointed @@ -10,6 +12,8 @@ import platform.posix.realpath import kotlinx.cinterop.allocArray import platform.posix.getcwd +private const val HOME_VAR: String = "HOME" + actual val FS_DELIMETER: String = "/" actual fun unzip(zipFile: File, outputDir: Directory) { @@ -17,7 +21,7 @@ actual fun unzip(zipFile: File, outputDir: Directory) { } actual fun homePath(): String = - getpwuid(getuid())?.pointed?.pw_dir?.toKString() ?: throw Exception("Failed to locate home dir") + getEnv(HOME_VAR) ?: getpwuid(getuid())?.pointed?.pw_dir?.toKString() ?: throw Exception("Failed to locate home dir") actual fun addExecutablePermissions(file: File) { runProcess("chmod +x ${file.path}")