Skip to content

Commit 27d7306

Browse files
#430: Add internal root field
1 parent d7acaca commit 27d7306

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

core/linux/src/internal/TimeZoneNative.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ private val tzdb = runCatching { TzdbOnFilesystem() }
2020

2121
@OptIn(ExperimentalForeignApi::class)
2222
private fun getTimezoneFromEtcTimezone(): String? {
23-
val timezoneContent = Path.fromString("/etc/timezone").readBytes()?.toKString()?.trim() ?: return null
24-
val zoneId = chaseSymlinks("/usr/share/zoneinfo/$timezoneContent")
23+
val timezoneContent = Path.fromString("${root}etc/timezone").readBytes()?.toKString()?.trim() ?: return null
24+
val zoneId = chaseSymlinks("${root}usr/share/zoneinfo/$timezoneContent")
2525
?.splitTimeZonePath()?.second?.toString()
2626
?: return null
2727

28-
val zoneInfoBytes = Path.fromString("/usr/share/zoneinfo/$zoneId").readBytes() ?: return null
29-
val localtimeBytes = Path.fromString("/etc/localtime").readBytes() ?: return null
28+
val zoneInfoBytes = Path.fromString("${root}usr/share/zoneinfo/$zoneId").readBytes() ?: return null
29+
val localtimeBytes = Path.fromString("${root}etc/localtime").readBytes() ?: return null
3030

3131
if (!localtimeBytes.contentEquals(zoneInfoBytes)) {
3232
val displayTimezone = when (timezoneContent) {
3333
zoneId -> "'$zoneId'"
3434
else -> "'$timezoneContent' (resolved to '$zoneId')"
3535
}
3636
throw IllegalTimeZoneException(
37-
"Timezone mismatch: /etc/timezone specifies $displayTimezone " +
38-
"but /etc/localtime content differs from /usr/share/zoneinfo/$zoneId"
37+
"Timezone mismatch: ${root}etc/timezone specifies $displayTimezone " +
38+
"but ${root}etc/localtime content differs from ${root}usr/share/zoneinfo/$zoneId"
3939
)
4040
}
4141

core/tzdbOnFilesystem/src/internal/TzdbOnFilesystem.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ internal fun tzdbPaths(defaultTzdbPath: Path?) = sequence {
4747
currentSystemTimeZonePath?.splitTimeZonePath()?.first?.let { yield(it) }
4848
}
4949

50-
internal val currentSystemTimeZonePath get() = chaseSymlinks("/etc/localtime")
50+
internal var root: String = "/"
51+
52+
internal val currentSystemTimeZonePath get() = chaseSymlinks("${root}etc/localtime")
5153

5254
/**
5355
* Given a path like `/usr/share/zoneinfo/Europe/Berlin`, produces `/usr/share/zoneinfo to Europe/Berlin`.

0 commit comments

Comments
 (0)