From 4a39f676490c7f6207d8e253af7a435aaa3fcda9 Mon Sep 17 00:00:00 2001 From: Brage Date: Sun, 14 Jan 2024 16:05:47 +0100 Subject: [PATCH] Minor update --- .../iktdev/mediaprocessing/shared/common/Utils.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/shared/common/src/main/kotlin/no/iktdev/mediaprocessing/shared/common/Utils.kt b/shared/common/src/main/kotlin/no/iktdev/mediaprocessing/shared/common/Utils.kt index a68f14f6..0f5cf88a 100644 --- a/shared/common/src/main/kotlin/no/iktdev/mediaprocessing/shared/common/Utils.kt +++ b/shared/common/src/main/kotlin/no/iktdev/mediaprocessing/shared/common/Utils.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.delay import mu.KotlinLogging import java.io.File import java.io.RandomAccessFile +import java.net.InetAddress private val logger = KotlinLogging.logger {} @@ -32,8 +33,17 @@ suspend fun limitedWhile(condition: () -> Boolean, maxDuration: Long = 500 * 60, } fun getComputername(): String { - return listOfNotNull( + val netHostname = try { + val host = InetAddress.getLocalHost() + listOf(host.hostName, host.canonicalHostName) + } catch (e: Exception) { + emptyList() + }.filterNot { it.isNullOrBlank() } + + val envs = listOfNotNull( System.getenv("hostname"), System.getenv("computername") - ).firstOrNull() ?: "UNKNOWN_SYSTEM" + ) + + return (envs + netHostname).firstOrNull() ?: "UNKNOWN_SYSTEM" } \ No newline at end of file