Skip to content

Commit 29276fe

Browse files
authored
Fix some files with dots in names being considered time zones (#395)
According to the authoritative implementation https://github.com/tzinfo/tzinfo/blob/9953fc092424d55deaea2dcdf6279943f3495724/lib/tzinfo/data_sources/zoneinfo_data_source.rb#L442 , all files with dots in their names aren't valid time zones. Now we implement the same logic.
1 parent 11c5157 commit 29276fe

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

core/tzdbOnFilesystem/src/internal/TzdbOnFilesystem.kt

+5-16
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,13 @@ internal class TzdbOnFilesystem(defaultTzdbPath: Path? = null): TimeZoneDatabase
3030
private val tabPaths = listOf("zone1970.tab", "zone.tab", "tab/zone_sun.tab")
3131

3232
/** The files that sometimes lie in the `zoneinfo` directory but aren't actually time zones. */
33-
private val tzdbUnneededFiles = setOf(
33+
private val tzdbUnneededFiles: Regex = Regex(
3434
// taken from https://github.com/tzinfo/tzinfo/blob/9953fc092424d55deaea2dcdf6279943f3495724/lib/tzinfo/data_sources/zoneinfo_data_source.rb#L88C29-L97C21
35-
"+VERSION",
36-
"leapseconds",
37-
"localtime",
38-
"posix",
39-
"posixrules",
40-
"right",
41-
"SECURITY",
42-
"src",
43-
"timeconfig",
35+
"\\+VERSION|leapseconds|localtime|posix|posixrules|right|SECURITY|src|timeconfig|" +
36+
// replicating https://github.com/tzinfo/tzinfo/blob/9953fc092424d55deaea2dcdf6279943f3495724/lib/tzinfo/data_sources/zoneinfo_data_source.rb#L442
37+
".*\\..*|" +
4438
// taken from https://github.com/HowardHinnant/date/blob/ab37c362e35267d6dee02cb47760f9e9c669d3be/src/tz.cpp#L2863-L2874
45-
"Factory",
46-
"iso3166.tab",
47-
"zone.tab",
48-
"zone1970.tab",
49-
"tzdata.zi",
50-
"leap-seconds.list"
39+
"Factory"
5140
)
5241

5342
/** The directories checked for a valid timezone database. */

core/tzdbOnFilesystem/src/internal/filesystem.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal fun chaseSymlinks(name: String): Path? = memScoped {
1717
internal fun Path.containsFile(file: String): Boolean = access("$this/$file", F_OK) == 0
1818

1919
internal fun Path.tryTraverseDirectory(
20-
exclude: Set<String> = emptySet(),
20+
exclude: Regex,
2121
stripLeadingComponents: Int = this.components.size,
2222
maxDepth: Int = 100,
2323
actionOnFile: (Path) -> Unit
@@ -29,7 +29,7 @@ internal fun Path.tryTraverseDirectory(
2929
val entry = readdir(handler) ?: break
3030
val name = entry.pointed.d_name.toKString()
3131
if (name == "." || name == "..") continue
32-
if (name in exclude) continue
32+
if (exclude.matches(name)) continue
3333
val path = Path(isAbsolute, components + name)
3434
val isDirectory = path.tryTraverseDirectory(
3535
exclude, stripLeadingComponents, maxDepth = maxDepth - 1, actionOnFile

0 commit comments

Comments
 (0)