Skip to content

Commit

Permalink
Respect HOME variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ololoshechkin committed Jun 17, 2022
1 parent bee37c6 commit 91217d9
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,14 +12,16 @@ 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) {
runProcess("unzip ${zipFile.path} -d ${outputDir.path}")
}

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}")
Expand Down

0 comments on commit 91217d9

Please sign in to comment.