Skip to content

Commit ed5d4d8

Browse files
committed
Fix chasing symlinks
1 parent 8f2bf15 commit ed5d4d8

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

core/nix/src/internal/TzdbOnFilesystem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private val tzdbPaths = sequence {
5050

5151
// taken from https://github.com/HowardHinnant/date/blob/ab37c362e35267d6dee02cb47760f9e9c669d3be/src/tz.cpp#L3951-L3952
5252
internal fun pathToSystemDefault(): Pair<Path, Path>? {
53-
val info = Path(true, listOf("etc", "localtime")).chaseSymlinks().first
53+
val info = Path(true, listOf("etc", "localtime")).chaseSymlinks()
5454
val i = info.components.indexOf("zoneinfo")
5555
if (!info.isAbsolute || i == -1 || i == info.components.size - 1) return null
5656
return Pair(
@@ -60,5 +60,5 @@ internal fun pathToSystemDefault(): Pair<Path, Path>? {
6060
}
6161

6262
internal actual val systemTzdb: TimezoneDatabase = tzdbPaths.find {
63-
it.chaseSymlinks().second?.isDirectory == true
63+
it.chaseSymlinks().check()?.isDirectory == true
6464
}?.let { TzdbOnFilesystem(it) } ?: throw IllegalStateException("Could not find the path to the timezone database")

core/nix/src/internal/filesystem.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ internal class Path(val isAbsolute: Boolean, val components: List<String>) {
5353
}
5454
}
5555

56-
internal fun Path.chaseSymlinks(): Pair<Path, PathInfo?> {
56+
internal fun Path.chaseSymlinks(): Path {
5757
var realPath = this
58-
var stat: PathInfo? = realPath.check()
59-
while (stat?.isSymlink == true) {
60-
stat = null
58+
while (true) {
6159
realPath = realPath.readLink() ?: break
62-
stat = realPath.check() ?: break
6360
}
64-
return realPath to stat
61+
return realPath
6562
}
6663

6764
// `stat(2)` lists the other available fields

0 commit comments

Comments
 (0)