Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some files with dots in names being considered time zones #395

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions core/tzdbOnFilesystem/src/internal/TzdbOnFilesystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,13 @@ internal class TzdbOnFilesystem(defaultTzdbPath: Path? = null): TimeZoneDatabase
private val tabPaths = listOf("zone1970.tab", "zone.tab", "tab/zone_sun.tab")

/** The files that sometimes lie in the `zoneinfo` directory but aren't actually time zones. */
private val tzdbUnneededFiles = setOf(
private val tzdbUnneededFiles: Regex = Regex(
// taken from https://github.com/tzinfo/tzinfo/blob/9953fc092424d55deaea2dcdf6279943f3495724/lib/tzinfo/data_sources/zoneinfo_data_source.rb#L88C29-L97C21
"+VERSION",
"leapseconds",
"localtime",
"posix",
"posixrules",
"right",
"SECURITY",
"src",
"timeconfig",
"\\+VERSION|leapseconds|localtime|posix|posixrules|right|SECURITY|src|timeconfig|" +
// replicating https://github.com/tzinfo/tzinfo/blob/9953fc092424d55deaea2dcdf6279943f3495724/lib/tzinfo/data_sources/zoneinfo_data_source.rb#L442
".*\\..*|" +
// taken from https://github.com/HowardHinnant/date/blob/ab37c362e35267d6dee02cb47760f9e9c669d3be/src/tz.cpp#L2863-L2874
"Factory",
"iso3166.tab",
"zone.tab",
"zone1970.tab",
"tzdata.zi",
"leap-seconds.list"
"Factory"
)

/** The directories checked for a valid timezone database. */
Expand Down
4 changes: 2 additions & 2 deletions core/tzdbOnFilesystem/src/internal/filesystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal fun chaseSymlinks(name: String): Path? = memScoped {
internal fun Path.containsFile(file: String): Boolean = access("$this/$file", F_OK) == 0

internal fun Path.tryTraverseDirectory(
exclude: Set<String> = emptySet(),
exclude: Regex,
stripLeadingComponents: Int = this.components.size,
maxDepth: Int = 100,
actionOnFile: (Path) -> Unit
Expand All @@ -29,7 +29,7 @@ internal fun Path.tryTraverseDirectory(
val entry = readdir(handler) ?: break
val name = entry.pointed.d_name.toKString()
if (name == "." || name == "..") continue
if (name in exclude) continue
if (exclude.matches(name)) continue
val path = Path(isAbsolute, components + name)
val isDirectory = path.tryTraverseDirectory(
exclude, stripLeadingComponents, maxDepth = maxDepth - 1, actionOnFile
Expand Down