Skip to content

Commit 7105210

Browse files
#430: Rename root to systemTimezoneSearchRoot
1 parent 2198821 commit 7105210

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

core/linux/src/internal/TimeZoneNative.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ private val tzdb = runCatching { TzdbOnFilesystem() }
2222
// See: https://github.com/Kotlin/kotlinx-datetime/issues/430
2323
@OptIn(ExperimentalForeignApi::class)
2424
private fun getTimezoneFromEtcTimezone(): String? {
25-
val timezoneContent = Path.fromString("${root}etc/timezone").readBytes()?.toKString()?.trim() ?: return null
26-
val zoneId = chaseSymlinks("${root}usr/share/zoneinfo/$timezoneContent")
25+
val timezoneContent = Path.fromString("${systemTimezoneSearchRoot}etc/timezone").readBytes()?.toKString()?.trim() ?: return null
26+
val zoneId = chaseSymlinks("${systemTimezoneSearchRoot}usr/share/zoneinfo/$timezoneContent")
2727
?.splitTimeZonePath()?.second?.toString()
2828
?: return null
2929

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

3333
if (!localtimeBytes.contentEquals(zoneInfoBytes)) {
3434
val displayTimezone = when (timezoneContent) {
3535
zoneId -> "'$zoneId'"
3636
else -> "'$timezoneContent' (resolved to '$zoneId')"
3737
}
3838
throw IllegalTimeZoneException(
39-
"Timezone mismatch: ${root}etc/timezone specifies $displayTimezone " +
40-
"but ${root}etc/localtime content differs from ${root}usr/share/zoneinfo/$zoneId"
39+
"Timezone mismatch: ${systemTimezoneSearchRoot}etc/timezone specifies $displayTimezone " +
40+
"but ${systemTimezoneSearchRoot}etc/localtime content differs from ${systemTimezoneSearchRoot}usr/share/zoneinfo/$zoneId"
4141
)
4242
}
4343

core/linux/test/TimeZoneNativeTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package kotlinx.datetime.test
77

88
import kotlinx.datetime.IllegalTimeZoneException
99
import kotlinx.datetime.TimeZone
10-
import kotlinx.datetime.internal.root
10+
import kotlinx.datetime.internal.systemTimezoneSearchRoot
1111
import kotlin.test.Test
1212
import kotlin.test.assertEquals
1313
import kotlin.test.assertFailsWith
@@ -73,12 +73,12 @@ class TimeZoneNativeTest {
7373
const val RESOURCES = "./linux/test/time-zone-native-test-resources/"
7474

7575
private fun withFakeRoot(fakeRoot: String, action: () -> Unit) {
76-
val defaultRoot = root
77-
root = fakeRoot
76+
val defaultRoot = systemTimezoneSearchRoot
77+
systemTimezoneSearchRoot = fakeRoot
7878
try {
7979
action()
8080
} finally {
81-
root = defaultRoot
81+
systemTimezoneSearchRoot = defaultRoot
8282
}
8383
}
8484
}

core/tzdbOnFilesystem/src/internal/TzdbOnFilesystem.kt

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

50-
internal var root: String = "/"
50+
internal var systemTimezoneSearchRoot: String = "/"
5151

52-
internal val currentSystemTimeZonePath get() = chaseSymlinks("${root}etc/localtime")
52+
internal val currentSystemTimeZonePath get() = chaseSymlinks("${systemTimezoneSearchRoot}etc/localtime")
5353

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

0 commit comments

Comments
 (0)